Home > Blockchain >  how can i solve the problem CORS policy on react js
how can i solve the problem CORS policy on react js

Time:05-26

from origin 'http://localhost:3003' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

when i post request using the other domain serves how i solve the problem!!

CodePudding user response:

I installed the cors unblock extension in Google Chrome and no more problems to me.

CodePudding user response:

in your node.js backend add:

app.use(cors({origin: true, credentials: true}));

also you can try installing this chrome extension. it fixed the issue for me

CodePudding user response:

For development you can use proxy to localhost:3003. Write this line in package.json of react project. "proxy": "http://localhost:3003".

To solve this issue, you will have to do in backend, for example if you backend is in nodejs then you can use CORS package.

Install cors package.

npm i cors

and then in your nodejs file write this

var cors = require('cors');
app.use(cors())

To configure cors you can refer documentation

  • Related