跨域报错 :

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3022' is therefore not allowed access.

express 设置了跨域不起作用 解决

 

 

按照网上方法  :在入口文件中添加了以下代码 

express 设置了跨域不起作用 解决

// 解决跨域问题
// app.all('*', function(req, response, next) {
//     //设置允许跨域的域名,*代表允许任意域名跨域
//     response.header("Access-Control-Allow-Origin", "*");
//     //允许的header类型
//     response.header("Access-Control-Allow-Headers", "X-Requested-With");
//     //跨域允许的请求方式
//     response.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
//     //设置响应头信息
//     response.header("X-Powered-By",' 3.2.1')
//     response.header("Content-Type", "application/json;charset=utf-8");

//     next();

// });

最后解决 : 只是一个代码先后的问题  node代码从上往下执行  

express 设置了跨域不起作用 解决

 

 

相关文章:

  • 2021-11-01
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2021-06-15
相关资源
相似解决方案