-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsocketProxy.js
More file actions
64 lines (53 loc) · 1.44 KB
/
socketProxy.js
File metadata and controls
64 lines (53 loc) · 1.44 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Created by backand on 1/14/16.
*/
//
// Setup our server to proxy standard HTTP requests
//
process.chdir(__dirname);
var http = require('https'),
fs = require('fs'),
httpProxy = require('http-proxy');
var config = require('./configFactory').getConfig();
var otherServerAddress = config.socketConfig.proxyIp;
httpProxy.createServer({
ssl: {
pfx: fs.readFileSync(config.socketConfig.pfxPath),
passphrase: '123456'
},
ws : true,
target: 'https://'+ otherServerAddress +':4000',
secure: false // Depends on your needs, could be false.
}).on('error', function(e) {
console.log(JSON.stringify(e, null, ' '))
}).listen(4000);
/*
console.log('start server on port: ' + config.socketConfig.serverPort + ' to ' + otherServerAddress);
// for production
var options = {
pfx: fs.readFileSync(config.socketConfig.pfxPath),
passphrase: '123456'
};
var proxy = new httpProxy.createProxyServer({
ssl: {
fx: fs.readFileSync(config.socketConfig.pfxPath),
passphrase: '123456'
},
secure : true,
target: {
host: otherServerAddress,
port: config.socketConfig.serverPort
}
});
var proxyServer = http.createServer(options,function (req, res) {
proxy.web(req, res);
});
//
// Listen to the `upgrade` event and proxy the
// WebSocket requests as well.
//
proxyServer.on('upgrade', function (req, socket, head) {
console.log('upgrade');
proxy.ws(req, socket, head);
});
proxyServer.listen(config.socketConfig.serverPort);*/