EGG框架设置跨域访问

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'
};

 

重启egg服务, done.

 

 

posted @ 2022-03-21 10:08  幻河  阅读(402)  评论(0编辑  收藏  举报