记得开心=。=|

node接口跨域

node接口跨域

解决方案

  // 解决跨域问题
  app.all("*",function(req,res,next){
      // 设置允许跨域的域名,*代表允许任意域名跨域
      res.header('Access-Control-Allow-Origin','*');
      // 允许的header类型
      res.header('Access-Control-Allow-Headers','content-type');
      // 跨域允许的请求方式
      res.header('Access-Control-Allow-Methods','DELETE,PUT,POST,GET,OPTIONS');
      if(req.method.toLowerCase() == 'options')
          res.send(200); // 让options 尝试请求快速结束
      else
          next();
  })

本文作者:HuangBingQuan

本文链接:https://www.cnblogs.com/bingquan1/p/16791732.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   HuangBingQuan  阅读(56)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 不将就 码农权
  2. 2 Bleeding Love 码农权
  3. 3 想你念你 码农权
想你念你 - 码农权
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

Not available