简体   繁体   中英

React + Express RESTful API calls

I'm trying to make a full-stack app (Express on the backend and React on the front) and I'm running into a problem. The server and UI are both being tested in my DEV environment on localhost, but with different port numbers. Making API calls from the frontend to the backend are resulting in CORS errors, because they're both running on different ports. I know a solution for this would be to implement server-side rendering, but due to a limitation of a 3rd party library that I'm using, I am unable to do this.

So I'm wondering what the best solution would be in this case. Simply placing the ("Access-Control-Allow-Origin", "*") header fixes everything, but I'm not a fan of doing this. Does anyone have any other suggestions?

Much appreciated--Thank you!

您需要启用CORS,或者可以使用“ Access-Control-Allow-Origin”,“ IP:PORT”指定地址。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM