This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-06
Channels
- # babashka-sci-dev (56)
- # beginners (13)
- # biff (3)
- # calva (24)
- # cider (2)
- # clj-together (2)
- # clojure (38)
- # clojure-europe (6)
- # clojure-norway (2)
- # clojurescript (1)
- # cursive (5)
- # introduce-yourself (3)
- # pedestal (4)
- # polylith (5)
- # portal (11)
- # re-frame (7)
- # reitit (6)
- # shadow-cljs (12)
- # spacemacs (5)
- # sql (7)
- # tools-deps (1)
Hi All
How do I add CORS support for Reitit? Pls advise.
Found something here [https://clojurians-log.clojureverse.org/reitit/2020-05-10]
@manas.marthi This will probably get you going
(defn allow-cross-origin
([handler]
(allow-cross-origin handler "*"))
([handler allowed-origins]
(fn [request]
(if (= (:request-method request) :options)
(-> {:status 200 :body ""}
(assoc-in [:headers "Access-Control-Allow-Headers"] "*")
(assoc-in [:headers "Access-Control-Allow-Origin"] allowed-origins)
(assoc-in [:headers "Access-Control-Allow-Methods"] "HEAD,GET,POST,DELETE"))
(-> (handler request)
(assoc-in [:headers "Access-Control-Allow-Headers"] "*")
(assoc-in [:headers "Access-Control-Allow-Origin"] allowed-origins)
(assoc-in [:headers "Access-Control-Allow-Methods"] "HEAD,GET,POST,DELETE"))))))
Then just add it in the :middleware key and adjust as needed 1
Thank you