Fork me on GitHub
#reitit
<
2018-10-25
>
ikitommi05:10:10

@shaun-mahood only thing that should be different is that Compojure has custom coercion from different types to responses, e.g. you can return a File or a String from a handler and they are coerced into response of status 200, with right headers and the thing as body.

shaun-mahood17:10:25

I figured out what was going on - I had my parameters wrong and the blank file was a result of that. Thanks for the help!

ikitommi05:10:19

reitit doesn't have that, so one needs to return actual response objects (or async wrappers with reitit-http)

shaun-mahood05:10:10

@ikitommi Ok thanks, I’ll see if I can figure out where I went wrong tomorrow.

shaolang09:10:04

@ikitommi Thanks for the warm welcome! 🙂 I probably am missing something; I keep getting Invalid anti-forgery token when transiting to /sign-in, and I could not figure why... 😞 I have been pulling my hair over the past few days figuring out before I decided to ask for help. Should I post this on SO, instead of bothering you?

(ns t.core
  (:require [immutant.web :as web]
            [reitit.ring :as ring]
            [ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
            [ring.middleware.content-type :refer [wrap-content-type]]
            [ring.middleware.params :refer [wrap-params]]
            [ring.middleware.keyword-params :refer [wrap-keyword-params]]
            [ring.middleware.session :refer [wrap-session]]
            [ring.util.anti-forgery :refer [anti-forgery-field]]
            [ring.util.response :as res]))


(defn render-index [_req]
  (res/response (str "<form action='/sign-in' method='post'>"
                     (anti-forgery-field)
                     "<button>Sign In</button></form>")))

(defn sign-in [{:keys [params session]}]
  (println "params: " params
           "session:" session)
  (res/redirect "/index.html"))

(defn wrap-af [handler]
  (-> handler
      wrap-anti-forgery
      wrap-session
      wrap-keyword-params
      wrap-params))

(def app
  (ring/ring-handler
   (ring/router [["/index.html" {:get render-index
                                 :middleware [[wrap-content-type]
                                              [wrap-af]]}]
                 ["/sign-in"    {:post sign-in
                                 :middleware [wrap-af]}]])))

(defn -main [& args]
  (web/run app {:host "localhost" :port 7777}))