Web前端之路让前端飞Node.js

egg.js之解决跨域问题(egg-cors)

2018-11-21  本文已影响10人  李佳明先生
1.下载 egg-cors 包
npm i egg-cors --save
2.在plugin.js中设置开启cors
exports.cors = {
  enable: true,
  package: 'egg-cors',
};
3.在config.default.js中配置
// add your config here
config.middleware = [];
//多出来的配置==========
config.security = {
  csrf: {
    enable: false,
    ignoreJSON: true
  },
  domainWhiteList: ['http://localhost:8080']
};
config.cors = {
  origin:'*',
  allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
};
上一篇 下一篇

猜你喜欢

热点阅读