I'm trying to put multiple sails server on same server, to do that I want to put a node http-proxy that redirect every domain on the right server like this :
var http = require('http'),
httpProxy = require('http-proxy'),
proxy = httpProxy.createProxyServer({}),
url = require('url');
http.createServer(function(req, res)
{
var hostname = req.headers.host.split(":")[0];
var pathname = url.parse(req.url).pathname;
switch(hostname)
{
case 'example.com':
proxy.web(req, res, { target: 'http://localhost:8080' });
break;
case 'dev.example.com':
proxy.web(req, res, { target: 'http://localhost:8081' });
break;
default:
proxy.web(req, res, { target: 'http://localhost:80' });
}
}).listen(80, function() {
console.log('proxy listening on port 80');
});
But with this after a new page is called I have this error and proxy crash :
/var/www/default/node_modules/http-proxy/lib/http-proxy/index.js:119
throw err;
^
Error: socket hang up
at createHangUpError (_http_client.js:215:15)
at Socket.socketCloseListener (_http_client.js:247:23)
at Socket.emit (events.js:129:20)
at TCP.close (net.js:485:12)
I suppose I missed some code to also forward sockets but how can I do that ? Is this kind of proxy strong enough for production ?