Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why would the cljs-http.client request be blocked by the cors policy if the clj-http.client request isn't? #127

Open
zendevil opened this issue Mar 15, 2020 · 1 comment

Comments

@zendevil
Copy link

I make a request like so using clj-http.client

(http/get "https://www.example.com/bar")

and get a response with status 200.

However, when I make the same request with cljs-http.client like so:

(go (let [response (<! (http/get (str "https://www.example.com" "/bar")))]
         (prn response)))

I get a response with status 0, and in the browser it says that it's been blocked by the cors policy.

Why would the cljs-http.client request be blocked by the cors policy if the clj-http.client request isn't? I have manually set the headers in ring like so:

(defn response [data & [status]]
  {:status (or status 200)
   :headers {"Content-Type" "application/edn"
             "Access-Control-Allow-Headers" "Content-Type"
             "Access-Control-Allow-Origin" "*"
             "Access-Control-Request-Method" "GET"}
   :body (pr-str data)})

I wrap my response for route "bar" with the function response above.

@victorb
Copy link

victorb commented Oct 30, 2020

Any chance you're calling clj-http.client from a Clojure context (instead of ClojureScript)? AFAIK, clj-http only works in Clojure, so it's running server-side, where there is no CORS restrictions, only the browser requests has to follow the rules of CORS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants