So I have this nodejs proxy:
var http = require('http');
var httpProxy = require('http-proxy');
var routes = [
'http://127.0.0.1:80',
'http://127.0.0.1:8001'
];
var proxy = new httpProxy.createProxyServer({});
var proxyServer = http.createServer(function (req, res) {
var route=0;
var split1=req.url.split('/');
if (split1.length>0) {
if(split1[1]=="socket.io"){
route=1;
}
}
proxy.web(req, res, {target: routes[route]});
});
proxyServer.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head, {target: routes[1]});
});
proxyServer.listen(80,"x.x.x.x");
It listens on port 80 and analyses each request. If it's a normal HTTP request, it gets directed to 127.0.0.1:80. If it's a websocket request (socket.io variety), it gets directed to 127.0.0.1:8001.
Everything seems to work fine.
But I don't have any exception handling.
Can anyone suggest any tips and/or things to watch out for?
Please bear in mind that I'm not a networking expert, nor do I have much experience with node.js. I guess experienced people can spot the big holes in what I'm doing very quickly, hence me posting here.