I know there are many responses about this issue but in my case I am running the server and the client side, I have changed the Access-Control-Allow-Origin in my header but still...
I have added the setHeader in my API response but I am still getting the same error. My app.post() is the next:
app.post("/api/todo", (req, res) => {
Todos.create( req.body)
.then(doc => {
res.header("Access-Control-Allow-Origin", "*")
res.status(200).json(doc);
})
.catch(() => {
res.status(500).json({error: "Could not CREATE the Document"});
})
I did the same one for a GET request and it worked, as I was facing the same problem before. In this case, with POST request, even though I added that line of code changing the response header I still get the same error.
Could anyone help ?