title: Getting Node-http-proxy to work with socket.io?
body: <p>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. </p>
  
  <p>(I pretty much just copy the README from node-http-proxy)</p>
  
  <pre><code>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});
  </code></pre>
  
  <p>And this is my client.js on the browser. </p>
  
  <pre><code>var socket = io.connect('http://localhost', {'sync disconnect on unload': false});
  </code></pre>
  
  <p>Somehow, io.connect is unable to connect to the nodejs server. I am getting this response from the io.connect: </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8" /&gt;
    &lt;title&gt;Action Controller: Exception caught&lt;/title&gt;
    &lt;style&gt;
      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; }
    &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Routing Error&lt;/h1&gt;
  &lt;p&gt;&lt;pre&gt;No route matches [GET] &amp;quot;/socket.io/1&amp;quot;&lt;/pre&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks
  !</p>