Skip to content
关注公众号,获取新课通知

关闭csrf开启跨域


安装

shell
npm i egg-cors --save

配置插件

js
// {app_root}/config/plugin.js
cors:{
  enable: true,
  package: 'egg-cors',
},
  • config / config.default.js 目录下配置
js
config.security = {
  // 关闭 csrf
  csrf: {
    enable: false,
  },
  // 跨域白名单
  domainWhiteList: ["http://localhost:3000"],
};
// 允许跨域的方法
config.cors = {
  origin: "*",
  allowMethods: "GET, PUT, POST, DELETE, PATCH",
};