http-proxy-middleware
一個輕鬆的配置代理服務器的中間件
開發中若接口文檔中接口有不同的IP和端口號,需要在option
下的router
屬性中配置path:轉向的端口和IP
,我這裏使用的是path
來匹配請求。參考文檔:http-proxy-middleware。
/**
* @file config for proxy, useful only in dev.
*
* @author taohang([email protected])
*
* 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'
}
}
}
};