// 步骤一:下载 egg-cors 包
cnpm i egg-cors --save
// 步骤二:plugin.js中设置开启cors
exports.cors = {
enable: true,
package: 'egg-cors',
};
// 步骤三:config.default.js中配置,注意配置覆盖的问题
config.security = {
// 关闭csrf
csrf: {
enable: false,
ignoreJSON: true
},
domainWhiteList: '*'
};
// 允许跨域
config.cors = {
origin:'*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
};
开发环境egg.js跨域
最新推荐文章于 2023-12-26 19:56:35 发布