title: Integrating websockets with a standard http.Server
body: <p>I have a simple <a href="http://nodejs.org/api/http.html#http_class_http_server" rel="noreferrer">webserver</a> like</p>
  
  <pre><code>var http = require('http'),
      url = require('url');
  var server = http.createServer(function (req, res) {
    var uri = url.parse(req.url).pathname;
    if (uri == '/') {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello World\n');
      return;
    }
  
    res.writeHead(404, {'Content-Type': 'text/plain'});
    res.end('File not found');
  });
  server.listen(0, '127.0.0.1');
  </code></pre>
  
  <p>I would now like to connect a single path (say, <code>/ws</code>) to a websocket, but leave the rest of the server unmodified.</p>
  
  <p>However, <a href="http://einaros.github.com/ws/" rel="noreferrer">ws</a> seems to require me to set up a dedicated server (with everything that that entails, like SSL termination, security configuration, and port allocation).</p>
  
  <p>How can I terminate just the path <code>/ws</code> to a websocket implementation?</p>