're-graph: CORS error with remote graphql server
I'm using re-graph to make a graphql query to a remote server:
(re-frame/dispatch [::re-graph/init
{:http-url "https://api.spacex.land/graphql"
:ws-url nil
:http-parameters
{:headers {"Access-Control-Allow-Headers" "Content-Type"
"Access-Control-Allow-Origin" "*"}}}])
But I keep getting this CORS error:
Access to XMLHttpRequest at 'https://api.spacex.land/graphql' from origin 'http://localhost:3449' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
Any idea what I need to do?
Solution 1:[1]
The Access-Control-Allow-Headers and Access-Control-Allow-Origin headers are supposed to be set by the Server not the Client. Removing them might be enough to fix it?
Solution 2:[2]
This worked for me:
(re-frame/dispatch [::re-graph/init
{:ws nil
:http {:url "http://api.example.com/graphql"
:impl {:oauth-token token
:with-credentials? false }}}])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thomas Heller |
| Solution 2 | Chin365 |
