简体   繁体   中英

CORS error when calling from the client?

I have a Nginx webserver in front of a Node REST API delivering JSON formatted data.

I also have a web app which consumes the above API and works fine for a majority of the requests it makes but sometimes, for certain URLs, the client gets a CORs error aka an 'Access-Control-Allow-Origin' error.

When I call the data again from the server of the web app it works fine again.

Could anyone shed some light on this issue.

I am using axios to call the API from the web app

You need to add CORS headers in response so that api can be accessed from browser. You can use npm cors package https://www.npmjs.com/package/cors

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