egg

作者: 宋song一 | 来源:发表于2020-01-03 16:04 被阅读0次

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

  1. 下载 egg-cors 包
    npm i egg-cors --save
  2. 在plugin.js中设置开启cors
exports.cors = {
  enable: true,
  package: 'egg-cors',
};
  1. 在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'
};

相关文章

网友评论

      本文标题:egg

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