Answer the question
In order to leave comments, you need to log in
How to properly enable CORS node express?
All the best!
What an incomprehensible problem I have with CORS, with a PUT or POST request, with GET - everything is fine.
On express server
app.put(`/requestRoute/`, async (req, res) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Redirect");
res.header("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS");
res.header("Access-Control-Allow-Credentials", true);
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Headers', 'Content-Type')
fetch('https://myserver/requestRoute/',{
method: 'PUT',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Credentials': 'true'
},
body: JSON.stringify({ "someKey": "someVal" })
})
add_header "Access-Control-Allow-Origin" "*";
add_header "Access-Control-Allow-Headers" "Origin, X-Requested-With, Content-Type, Accept,Authorization";
add_header "Access-Control-Request-Methods" "GET, POST, OPTIONS, PUT";
...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'.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question