安装egg-cors
npm install egg-cors --save
config/plugin.js
'use strict';
/** @type Egg.EggPlugin */
module.exports = {
// had enabled by egg
// static: {
// enable: true,
// }
cors: {
enable: true,
package: 'egg-cors'
}
};
config/config.default.js
config.security = {
csrf: {
enable: false
},
domainWhiteList: [ '*' ] //白名单
};
config.cors = {
origin: '*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS'
};
网友评论