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

2020-08-03  本文已影响0人  头发飘逸

地址:https://www.npmjs.com/package/egg-cors

下载 egg-cors 包

npm i egg-cors --save

在plugin.js中设置开启cors

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

在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'
};
上一篇 下一篇

猜你喜欢

热点阅读