hoplon / castra

HTTP remote procedure call handler for Clojure.
172 stars 25 forks source link

Refactor ring handler into middleware #3

Open micha opened 10 years ago

micha commented 10 years ago

Castra shouldn't return 404s. Instead it should pass through to the next handler. This would make it possible to chain multiple castra middleware, for example.

micrub commented 10 years ago

I have a question about chaining middleware in current castra state:

Is it possible to mix castra handler with compojure routes ?

(def server (atom nil))

(defn func1 []
    (do
      {:status 200
       :headers {"Content-Type" "text/json"}
       :body {:response {}})))

(defroutes handler
  (POST "/action" {params :params}
       (func1))

(defn app [port public-path]
  (->
    (handler)
    (castra 'example.api)
    (wrap-session {:store (cookie-store {:key "a 16-byte secret"})})
    (wrap-file public-path)
    (wrap-file-info)
    (wrap-multipart-params)
    (run-jetty {:join? false :port port})))