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.