Skip to content

Instantly share code, notes, and snippets.

@lightningspirit
Created August 2, 2018 09:10
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 lightningspirit/caa5bec0fcda5de00c8744945acf6e3e to your computer and use it in GitHub Desktop.
Save lightningspirit/caa5bec0fcda5de00c8744945acf6e3e to your computer and use it in GitHub Desktop.
This is a small portion of the core.cj file for call-timeline that aimed to add CORS support using two middlewares.
(defn wrap-options
[app]
(fn [request]
(if (= (request :request-method) :options)
(into request {:status 204})
(app request))))
(defn add-header
[r name value]
(assoc-in r [:headers name] value))
(defn wrap-cors
[app]
(fn
([request]
(-> (app request)
(add-header "Access-Control-Allow-Origin" "*")
(add-header "Access-Control-Allow-Methods" "GET, OPTIONS")
(add-header "Access-Control-Allow-Headers" "Content-Type, Authorization, X-Account-Id")))))
(def handler
(-> app
wrap-options
wrap-cors))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment