加载中...
  • egg.js之解决跨域问题(egg-cors)

    地址:https://www.npmjs.com/package/egg-cors

    下载 egg-cors 包

    1
    npm i egg-cors --save

    在plugin.js中设置开启cors

    1
    2
    3
    4
    exports.cors = {
    enable: true,
    package: 'egg-cors',
    };

    在config.default.js中配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    // add your config here
    config.middleware = [];
    //多出来的配置==========
    config.security = {
    csrf: {
    enable: false,
    ignoreJSON: true
    },
    domainWhiteList: ['http://localhost:8080']
    };
    config.cors = {
    origin:'*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
    };

     

    上一篇:
    egg.js 配置cors跨域
    下一篇:
    eggjs的参数校验模块egg-validate的使用
    本文目录
    本文目录