-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.js
42 lines (32 loc) · 1.05 KB
/
proxy.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
'use strict';
var https = require('https'),
httpProxy = require('http-proxy'),
config = JSON.parse(require('fs').readFileSync('config.json', 'utf8')),
stats = {
wsProxied: 0
};
function createProxy() {
var proxy, server;
httpProxy.setMaxSockets(65000);
proxy = new httpProxy.RoutingProxy();
server = https.createServer({
pfx: require('fs').readFileSync('cert.pfx')
});
server.on('request', function(request, response) {
proxy.proxyRequest(request, response, config.proxy_target);
});
server.on('upgrade', function(request, socket, head) {
stats.wsProxied++;
proxy.proxyWebSocketRequest(request, socket, head, config.proxy_target);
});
server.listen(config.proxy_port, function() {
console.log('Proxy server listening on port', config.proxy_port);
});
}
createProxy();
setInterval(function() {
console.log('stats', stats);
}, 5000);
require('./heapdump').startSnapshotServer(config.proxy_heapdump_port, function() {
console.log('heapdump snapshot enabled at http://localhost:' + config.proxy_heapdump_port + '/snapshot\n', config);
});