Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i solve the problem CORS policy on react js

Tags:

reactjs

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!!

like image 497
gemma Avatar asked Dec 29 '25 19:12

gemma


1 Answers

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

like image 69
Shikhar Awasthi Avatar answered Jan 01 '26 11:01

Shikhar Awasthi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!