美文网首页
Node.js Egg.js 跨域问题

Node.js Egg.js 跨域问题

作者: 李颖轩_LiYingxuan | 来源:发表于2018-11-12 17:22 被阅读42次

安装插件

npm i egg-cors --save

加载插件

配置文件 ./config/plugin.js 增加:

exports.cors = {
  enable: true,
  package: 'egg-cors',
};

设置参数

配置文件 ./config/config.default.js 增加:

// 禁用了CSRF安全检测
config.security = {
  csrf: {
    enable: false,
  }
};

config.cors = {
  origin: '*',
  allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
};

The end.

相关文章

网友评论

      本文标题:Node.js Egg.js 跨域问题

      本文链接:https://www.haomeiwen.com/subject/pqbcfqtx.html