项目场景:
在使用fetch或者axios时跨域报错
问题描述:
Access to XMLHttpRequest at 'http://localhost:3000/axios' from origin 'null' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response. axios.js:1141 POST http://localhost:3000/axios net::ERR_FAILED
Access to fetch at 'http://localhost:3000/books' from origin 'null' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
解决方案:
// 设置允许跨域访问该服务
app.all('*',