DEV Community

Discussion on: Reactjs fetch API request getting blocked by CORS policy

Collapse
mfurkankaya profile image
Furkan KAYA • Edited on

If your backend api is a nodejs and express project, you can use cors package from npm. It's so easy.

Collapse
saiavinashiitr profile image
Sai Avinash Duddupudi Author

what if I don't have control of the backend server? Is there a way I can bypass this CORS error for development purposes in my local?

Collapse
mfurkankaya profile image
Furkan KAYA

There should be but I really don't know. One more thing tht i know is; if you're using a production backend (somedomain.com/api), you can proxy it like: cors-anywhere.herokuapp.com/https:...

Thread Thread
saiavinashiitr profile image
Sai Avinash Duddupudi Author

wow.... It worked now... Thank you so much Furkan! :)

Thread Thread
mfurkankaya profile image
Furkan KAYA

I'm happy it worked. :D

Thread Thread
saiavinashiitr profile image
Sai Avinash Duddupudi Author • Edited on

hey, sometimes https://cors-anywhere.herokuapp.com is not working... is there any other similar one that I can use in place of this which is much more reliable?
Here is the Screenshot

Thread Thread
mfurkankaya profile image
Furkan KAYA

Man it's been long but i couldn't see your last comment. :D You can clone corsy-anywhere project to your local. Then you can proxy it like "localhost:8080/somedomain.com/api". Corsy anywhere github repo: github.com/Rob--W/cors-anywhere

Thread Thread
saiavinashiitr profile image
Sai Avinash Duddupudi Author

hey, no issues.... I have now contacted the backend team and they have whitelisted my domain. so all good for now!. Thanks Furkan for new insights:)