EggJS 設置代理實現跨域 egg-http-proxy


安裝:
npm i egg-http-proxy --save
// 或
yarn add egg-http-proxy
導入到egg項目里:
// 在config/plugin.js里面添加
exports.httpProxy = {
  enable: true,
  package: 'egg-http-proxy',
};

// 或者,在config/plugin.js的module.exports里面添加
module.exports = {
  httpProxy: {
    enable: true,
    package: 'egg-http-proxy',
  }
};
配置:
// 在config/config.default.js的module.exports里面添加
// 配置代理
config.httpProxy = {
  '/api': 'http://www.example.org'
};

// 或者
config.httpProxy = {
  '/api': {
    target: 'http://www.example.org',
    pathRewrite: {'^/api' : ''}
  }
};

.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM