Skip to content

Instantly share code, notes, and snippets.

@cpjolicoeur
Created June 17, 2020 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpjolicoeur/3352a87ffc0e1dd5a5347b3303fa8b4f to your computer and use it in GitHub Desktop.
Save cpjolicoeur/3352a87ffc0e1dd5a5347b3303fa8b4f to your computer and use it in GitHub Desktop.
CORS middleware for Joy framework
(defn cors [handler &opt opts]
(default opts @{})
(def defaults @{"Access-Control-Allow-Origin" "*"
"Access-Control-Allow-Methods" "GET, OPTIONS"
"Access-Control-Allow-Headers" "Content-Type"
"Access-Control-Max-Age 86400})
(def options (merge defaults opts))
(fn [request]
(if (= "OPTIONS" (get request :method))
@{:status 204, :body "" :headers options}
(let [response (handler request)]
(when response
(update response :headers merge options))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment