简体   繁体   中英

I am using heroku to test my application. how to solve cors problem?

Error: I am using heroku to test my application. Back (node.js - express) frontend written in react

When entering the site, an error occurs when receiving data

How to deal with it

Access to fetch at 'my-web_api/allCity' from origin 'my-web_api' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

You have to install cors(Cross-Origin Resource Sharing) package to avoid this type of error

npm i cors

and use it in your server.js file just like that

 const cors = require('cors')
 app.use(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