-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy.js
38 lines (33 loc) · 1.03 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
var fs = require('fs');
var http = require('http');
var https = require('https');
var httpProxy = require('http-proxy');
var uid = 502; //node-http-proxyを動作させるUserId
var sslkeyPath = '/etc/letsencrypt/live/goita.beta.or.jp/'
var options = {
key: fs.readFileSync(sslkeyPath + 'privkey.pem', 'utf8'),
cert: fs.readFileSync(sslkeyPath + 'cert.pem', 'utf8')
}
var proxy = httpProxy.createProxyServer({
target: "http://goita.beta.or.jp:8880",
ws: true
});
var server = http.createServer(function(req, res){
proxy.web(req, res);
});
server.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head);
});
var sslproxy = httpProxy.createServer({
target: "http://goita.beta.or.jp:8880",
ws: true,
secure: true,
ssl: options
});
server.listen(80, function(){
process.setuid(uid);
}); //root is required to run service on port 80.
sslproxy.listen(443, function(){
process.setuid(uid);
}); //root is required to run service on port 443.
console.log("proxy server started");