forked from shroomlife/docker-https-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
35 lines (28 loc) · 747 Bytes
/
proxy.js
File metadata and controls
35 lines (28 loc) · 747 Bytes
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
const { request } = require('http')
const proxy = (req, res, next, proxyHost) => {
const proxiedRequest = request(
{
host: [proxyHost, 'proxy'].join('.'),
port: process.env.REDIRECT_PORT || 80,
path: req.url,
method: req.method,
headers: {
...req.headers,
'X-FORWARDED-PROTO': req.protocol
}
},
response => {
res.writeHead(response.statusCode, response.headers)
response.pipe(res)
}
)
if(typeof req.rawBuffer !== 'undefined') {
proxiedRequest.write(req.rawBuffer)
}
proxiedRequest.on('error', (error) => {
console.error(`[${new Date().toISOString()}] ERROR: ${error.message}`)
next()
})
proxiedRequest.end()
}
module.exports = proxy