Problem with CORS in Reactjs application

Asked

Viewed 18 times

0

I checked on other questions but found no answer that fits my problem.

I have a Reactjs application that is on my localhost:3000 and I need to post for my API that is on my localhost:4000.

The sending of the data is blocked by CORS, but so far, I have done other tests in my API and everything is working correctly. I can even make the same request through India.

CORS API:

module.exports = (req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*')
    res.header('Access-Control-Allow-Methods', 'GET,POST,PATCH,DELETE')
    res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-with, Cotent-type, Accept, privatekey')
    next()
}

Requests in the React app are via Axios. Error:

inserir a descrição da imagem aqui

  • CORS is a policy implemented in your browser, programs such as Insomnia are not subject to these policies, so you do not have errors testing requests by this program. Your problem is that in your middleware, you are granting permissions for the header cotent-type, not for the content-type, syntax error, missing n.

  • Thank you very much and forgive my ignorance !

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.