I am trying to use node-http-proxy to direct traffic to port 3000 (my rails server) and port 8888 (my nodejs socket.io server). I am using node-http-proxy to act as a reverse proxy sitting on port 80.
(I pretty much just copy the README from node-http-proxy)
var proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: CONFIG.RAILS_PORT,
}
});
var server = http.createServer(function(req, res) {
//
// Proxy normal HTTP requests
//
proxy.proxyRequest(req, res);
});
server.on('upgrade', function(req, socket, head) {
//
// Proxy websocket request to another port
//
console.log('inside upgrade');
proxy.proxyWebSocketRequest(req, socket, head, {
host: 'localhost',
port: CONFIG.NODEJS_PORT
});
});
server.listen(80);
var WrappedServer = require('./wrappedServer').WrappedServer
var singleton = new WrappedServer();
singleton.run(CONFIG.NODEJS_PORT, {'log level': 2});
And this is my client.js on the browser.
var socket = io.connect('http://localhost', {'sync disconnect on unload': false});
Somehow, io.connect is unable to connect to the nodejs server. I am getting this response from the io.connect:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Action Controller: Exception caught</title>
<style>
body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
font-family: helvetica, verdana, arial, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
</style>
</head>
<body>
<h1>Routing Error</h1>
<p><pre>No route matches [GET] "/socket.io/1"</pre></p>
</body>
</html>
Any idea how I can get io.connect to connect to the nodejs server? I don't know how I can trigger io.connect to get to the server.upgrade bloc.
Thanks !