http-proxy-middleware代理轉發到不同的IP和端口

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'
            }
        }
    }
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章