npm install egg-cors --save
'use strict';
/** @type Egg.EggPlugin */
exports.cors = {
enable: true,
package: 'egg-cors',
};
config.security = {
csrf: {
enable: false,
},
domainWhiteList: [ '*' ],//允许访问接口的白名单,例如:http://localhost:8080 *表示均可访问
};
config.cors = {
origin: '*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
};