Created
August 2, 2018 09:10
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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