1234567891011121314151617181920212223242526 |
- (ns attendant.handler
- (:require
- [compojure.core :refer [defroutes ANY OPTIONS]]
- [compojure.route :refer [not-found]]
- [ring.util.response :refer [header]]))
- (defroutes app
- (OPTIONS "*" [] "")
- (ANY "/" [] "attendant server")
- (not-found "nothing here (yet)"))
- (defn make-handler []
- (fn [req]
- (let [body (some-> req
- :body
- (slurp)
- (not-empty)
- (read-string))
- new-req (cond-> req
- body (update :params merge body))]
- (-> (#'app new-req)
- (header "Access-Control-Allow-Methods" "GET, DELETE, POST, PUT, OPTIONS")
- (header "Access-Control-Allow-Origin" (get-in req [:headers "origin"]))
- (header "Access-Control-Allow-Credentials" "true")
- (header "Access-Control-Allow-Headers" "Content-Type")))))
|