Eggjs 设置跨域请求

1. 安装egg-cors

npm install  egg-cors --save

2.打开config/plugin.js

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

3.在config/config.default.js

  config.security = {
    csrf: {
      enable: false
    },
    domainWhiteList: [ '*' ]
  };
 config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS'
};

 

posted @ 2019-04-18 09:39  Mr丶Lee  阅读(7496)  评论(0)    收藏  举报