ring

pablore 2018-01-18T18:33:19.000090Z

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

seancorfield 2018-01-18T20:26:12.000997Z

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

seancorfield 2018-01-18T20:26:28.000756Z

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

pablore 2018-01-19T20:14:26.000508Z

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

seancorfield 2018-01-19T21:24:02.000157Z

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

seancorfield 2018-01-19T21:24:49.000563Z

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 #".*")]
  ...)

seancorfield 2018-01-19T21:25:35.000414Z

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