Eggjs解决跨域问题
1:先安装egg-cors插件
npm install egg-cors -s
或者
yarn add egg-cors
2:在config/plugin.ts开启egg-cors插件
const plugin: EggPlugin = {
// 其他的
cors: {
enable: true,
package: 'egg-cors'
}
// 其他的
};
3:在config/config.default.ts中进行配置
export default (appInfo: EggAppInfo) => {
// 其他的
config.cors = {
origin: '*',//域名+端口 或者 *(全匹配)
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
};
// 其他的
};