eggjs配置01 - 跨域配置

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