-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheth.js
52 lines (46 loc) · 1.41 KB
/
eth.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
45
46
47
48
49
50
51
52
const http = require('http')
const httpProxy = require('./node-http-proxy/lib/http-proxy')
const httpMode = process.env.HTTP_MODE
const targetUrl = process.env.TARGET_URL
const targetPort = process.env.TARGET_PORT
let proxy
let server
if(httpMode == 1) {
proxy = new httpProxy.createProxyServer({
target: targetUrl,
port: targetPort,
changeOrigin: true,
ignorePath: true,
hostRewrite: true,
followRedirects: true,
protocolRewrite: true
})
proxy.on('proxyRes', function(proxyRes, req, res) {
res.setHeader('Content-Type', 'application/json');
});
server = http.createServer(function(req, res) {
proxy.web(req, res)
})
}else {
proxy = new httpProxy.createProxyServer({
target: targetUrl,
port: targetPort,
changeOrigin: true,
ignorePath: true,
hostRewrite: true,
followRedirects: true,
protocolRewrite: true,
ws: true
})
server = http.createServer()
server.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head)
})
}
let port = Number(process.env.PROXY_PORT || 5050)
const increment = process.env.NODE_APP_INSTANCE
if(increment != null) {
port += Number(increment)
}
console.log(`--- ${httpMode == 1 ? 'Http' : 'Websocket'} mode --- \n--- Target: ${targetUrl}:${targetPort} - Listening at: ${port} ---`)
server.listen(port)