-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy.config.js
44 lines (38 loc) · 1.16 KB
/
proxy.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const os = require('os')
const networkInterfaces = os.networkInterfaces()
let ip = ''
for (const networkInterface of Object.values(networkInterfaces)) {
networkInterface.forEach(alias => {
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
ip = alias.address
}
})
}
const proxyObj = {}
// 与开发联调的时候由于未知 需手动填写
const devHostName = 'xxx.xx.x.xx'
const devServerPort = '8085'
// 代理路由表
const PROXY_ROUTER = {
'127.0.0.1': 'https://nei.hz.netease.com/api/', // 代理到nei环境
'proxy.netease.com': 'https://proxy.netease.com/', // 代理到测试环境
[ip]: `http://${devHostName}:${devServerPort}` // 代理到后端的ip环境
}
// 代理接口
const proxyTable = {
'/api': ''
}
Object.entries(proxyTable).forEach(([key, value], index) => {
proxyObj[key] = {
target: value || 'http://localhost:8080',
changeOrigin: true,
pathRewrite (path, req) {
return path.replace(/\/api/, '')
},
router (req) {
const hostname = req.headers.host.split(':')[0]
return PROXY_ROUTER[hostname] || 'http://localhost:8080'
}
}
})
module.exports = proxyObj