Fork me on GitHub
#reitit
<
2021-04-23
>
grounded_sage10:04:41

Is there a simple API first reitit demo. Curious as I am having trouble getting past cors issue. Not sure what I am missing.

grounded_sage10:04:22

What am I missing here?

(defn handler [_]
  {:status 200, :body "hello app"})

(def app
  (ring/ring-handler
   (ring/router
    ["/" {:get handler}]
    {:exception pretty/exception
     :data {:middleware [[wrap-cors :access-control-allow-origin [#".*"]
                          :access-control-allow-methods [:get :put :post :patch :delete]]]}})
   (ring/create-default-handler {:not-found (constantly {:status 404 :body "Not found"})})))

emil0r10:04:10

If you're using cljs-ajax you need withCredentials and corresponding middleware in the backend

emil0r11:04:07

And you need :options for CORS iirc for the preflight check from the browser

grounded_sage11:04:53

using cljs-http on the frontend. This answer still confuses me. Would be easier if I could see a code example. All ones I have seen in the wild do not work for me.

emil0r14:04:16

I can put together something later if no one else beats me to it

👍 1
emil0r14:04:11

See if you can move forward by adding :options to the CORS middleware

grounded_sage14:04:54

I find it strange how I've found like 5 different examples on how to handle CORS. Hard to tell which one is the more idiomatic way to do it in reitit. Given this is like a fundamental piece I would think there would be documentation right there on the library. Even if it is until a more bundled approach is achieved.

ikitommi14:04:03

PR welcome.

ikitommi14:04:07

would love to see cors, security headers etc. as builtins. 100% busy atm, so, contributions welcome.

miikka14:04:18

Just released reitit 0.5.13. A minor fix to create-resource-handler/create-file-handler and some doc and deps updates. https://github.com/metosin/reitit/blob/master/CHANGELOG.md#0513-2021-04-23

🎉 3