This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-23
Channels
- # announcements (5)
- # aws (4)
- # babashka (141)
- # beginners (139)
- # calva (35)
- # cider (5)
- # clj-kondo (27)
- # cljsrn (20)
- # clojure (37)
- # clojure-czech (5)
- # clojure-dev (26)
- # clojure-europe (11)
- # clojure-germany (1)
- # clojure-italy (1)
- # clojure-nl (3)
- # clojure-spec (17)
- # clojure-uk (16)
- # clojurescript (2)
- # conjure (1)
- # cursive (6)
- # datomic (20)
- # defnpodcast (1)
- # emacs (15)
- # fulcro (26)
- # honeysql (2)
- # instaparse (3)
- # jackdaw (4)
- # jobs (2)
- # lsp (70)
- # luminus (2)
- # meander (16)
- # missionary (2)
- # other-languages (151)
- # pathom (6)
- # portkey (13)
- # re-frame (13)
- # reagent (2)
- # reitit (43)
- # releases (1)
- # remote-jobs (1)
- # reveal (5)
- # rum (2)
- # sci (15)
- # shadow-cljs (37)
- # spacemacs (4)
- # tools-deps (8)
- # vim (20)
Is there a simple API first reitit demo. Curious as I am having trouble getting past cors issue. Not sure what I am missing.
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"})})))
If you're using cljs-ajax you need withCredentials and corresponding middleware in the backend
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.
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.
would love to see cors, security headers etc. as builtins. 100% busy atm, so, contributions welcome.
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
I've tried:
The interceptor way with this library: https://github.com/zerg000000/simple-cors
The {:data ...}
pattern found here: https://github.com/prestancedesign/todo-backend-clojure-reitit/blob/master/src/todo_backend/core.clj
This example here: https://github.com/metosin/reitit/issues/143#issuecomment-421781636
The example here (which uses options). https://clojurians-log.clojureverse.org/reitit/2020-05-10
Access to XMLHttpRequest at ' ' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
Hmh, I wonder what is going on. I tried the code with wrap-cors you pasted above and the following JavaScript served from a separate port and it seemed to work just fine:
fetch(' {
return resp.text();
}).then(function(body) {
console.log("body text:", body);
});
Looking at the browser developer tools, the response has the CORS headers it should have (`Access-Control-Allow-Origin: http://localhost:8000` etc)
No idea why I can't get it working then
https://github.com/miikka/reitit-cors-test here's the code i used. I mean, it just the code you posted, but still.
Yes was a GET request
Does the response from the server look otherwise okay? Like the status code, response body, tec?
{:status 0, :success false, :body "", :headers {}, :trace-redirects ["" ""], :error-code :http-error, :error-text " [0]"}
Has a CORS error
Could it possibly be from the frontend doing something wrong?
This is basically what I have atm. Obviously port being what the port is for server.
(ns app.core
(:require [cljs-http.client :as http]
[cljs.core.async :refer [go <!]]))
(go (let [response (<! (http/get ""))]
(prn response)
(prn (:status response))
(prn (:body response))))
I'm starting to run out of ideas. You could try to run the same request with curl and check that the output looks right, but otherwise I don't know what to do. (You can right-click that request in Chrome Network tab and select Copy -> Copy as cURL to get the ready-to-run command-line command)
haha the copy as curl works fine :man-shrugging::skin-tone-2:
I think there is something wrong with this client side http library
That was it. Thanks! Super annoying. Thank you for helping me spot that!