安裝:
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' : ''} } };
.