// 下载依赖
npm install egg-cors
// config/plugin.js
'use strict';
module.exports = {
cors:{
enable: true,
package: 'egg-cors',
}
};
// config/config.default.js
config.security = {
csrf: {
enable: false,
ignoreJSON: true
},
domainWhiteList: ['*']//[]中放放出的白名单,*代表所有
};
config.cors = {
origin:'*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
};