http-proxy-middleware
一个轻松的配置代理服务器的中间件
开发中若接口文档中接口有不同的IP和端口号,需要在option
下的router
属性中配置path:转向的端口和IP
,我这里使用的是path
来匹配请求。参考文档:http-proxy-middleware。
/**
* @file config for proxy, useful only in dev.
*
* @author taohang(taohang@baidu.com)
*
* The dev server is using http-proxy-middleware for proxying,
* so you can refer to its docs for detailed usage.
* see https://github.com/chimurai/http-proxy-middleware for documentation.
*/
module.exports = {
proxy: {
// proxy all requests starting with /api to target,
// use /*/* will proxy all requests starting with any string
// proxy useful only while path exist && option.target is exist
path: ['/eam/asset/', '/currentUser', '/eam/host/', '/eam/', '/platform/api/v1', '/apptree/v1',
'/apptreeNew', '/asset',
'/eam_task', '/taskNames', '/intervals', '/status', '/tasks', '/columns', '/network/subnet/physical'],
option: {
// the target to request
// target: 'http://10.130.71.24:8050', // 上线地址
// target: 'http://10.132.144.17:8009', // 测试地址
// target: 'http://10.132.144.17:8050', // 物理机资产地址
target: 'http://10.132.144.31:8010', // 资产测试地址
// changes the origin of the host header to the target URL
changeOrigin: true,
// object, adds request headers. (Example: {Cookie:'mycookie'})
headers: {
// get cookie by visit the target url
Cookie: ''
},
// 这里表示不同的path对应不同的转发 path: url
router: {
'/network/subnet/physical': 'http://10.132.144.31:8009'
}
}
}
};