egg.js 之跨域问题解决

1.安装 egg-cors

npm i egg-cors --save/cnpm i egg-cors --save

2.配置plugin.js

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

3.配置config.default.js

 config.security = {
    csrf: {
      enable: false,
      ignoreJSON: true
    },
    domainWhiteList: ['*']//[]中放放出的白名单,*代表所有
  };
  config.cors = {
    origin:'*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  };
posted @ 2020-06-03 17:39  HLLZ  阅读(1653)  评论(0编辑  收藏  举报