Fork me on GitHub
#ring
<
2018-01-18
>
pablore18:01:19

Hi! I’m using ring/compojure to setup a web microservice in clojure. I need CORS to integrate test it, is there any way to setup to :access-control-allow-origin [#"all"] Wildcard * is not working

seancorfield20:01:12

@pablore It should be a single regex, I believe. We have :access-control-allow-origin #".*" and that seems to work.

seancorfield20:01:28

(I assume you're talking about wrap-cors?)

pablore20:01:26

yes. For some reason, having #".*" caused a null pointer exception

seancorfield21:01:02

Well, #".*" is what we have so I doubt that was the cause of your NPE.

seancorfield21:01:49

Specifically, here's the code we have in production:

(let [h (ring-cors/wrap-cors handler
                               :access-control-allow-headers #{"accept"
                                                               "authorization"
                                                               "content-type"
                                                               "origin"}
                               :access-control-allow-methods [:delete :get
                                                              :patch :post :put]
                               ;; 24 hours (in seconds) -- note that only Firefox
                               ;; will honor this; other browsers cap lower!
                               :access-control-max-age "86400"
                               :access-control-allow-origin #".*")]
  ...)

seancorfield21:01:35

(the ... part returns (fn [req] ...) and inside that it calls (h req) and handles the result)