Fork me on GitHub
#reitit
<
2020-11-15
>
benny07:11:16

i’m trying to expose my whole API with CORS allowing any origin, but I can’t seem to find a sweet spot on how to accomplish this. I have a structure like so

(def routes-a ["" {:coercion rcs/coercion} ["/foo" {:middleware [custom-mw-stack-1]}]])
(def routes-b ["" {:coercion rcs/coercion} ["/bar" {:middleware [custom-mw-stack-2]}]])
(def app (ring/ring-handler (ring/router [routes-a routes-b])))

Michaël Salihi08:11:24

@benny Maybe something like that

(def app (ring/ring-handler
          (ring/router
           [routes-a routes-b]
           {:data {:middleware [wrap-cors :access-control-allow-origin [#".*"]
                                          :access-control-allow-methods [:get :put :post :patch :delete]]}})))

benny04:11:06

that did the trick, thanks @UFBL6R4P3!

👍 3