- 安装插件:
egg-cors
yarn add egg-cors
- 配置
config/plugin.js:
module.exports = {
/* start */
crossOriginIsolated: {
enable: true,
package: 'egg-cors',
},
/* end */
};
- 配置
config/config.default.js:
config.security = {
csrf: {
enable: false,
},
domainWhiteList: ['*'],
};
config.cors = {
origin: '*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
};