地址: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'
};
网友评论