commit 11dc82acbcdc10352a01a0c2cc1db2066188d43e
Author: James Halliday
Date: Tue Oct 11 09:13:30 2011 +0000

Introducing bouncy, a websocket and https-capable http router proxy / load balancer in node.js!

It's super simple to use, just call bounce()!

var bouncy = require('bouncy');

bouncy(function (req, bounce) {
    if (req.headers.host === 'bouncy.example.com') {
        bounce(8000);
    }
    else if (req.headers.host === 'trampoline.example.com') {
        bounce(8001)
    }
}).listen(80);

You can bounce() to a port, a host, port, or a stream you open yourself.

Since bouncy is just parsing the http headers and sending along the raw tcp stream, you can use websockets on the place you bounce() to without writing any special code!

Bouncy uses node's delicious http parsing innards, so the req object you get is a bona-fide http.ServerRequest with all the fixins.

Plus, bouncy comes with a simple command-line tool if you have a static routing table kicking around in a json file. Just throw a routes.json like this one:

{
    "beep.example.com" : 8000,
    "boop.example.com" : 8001
}

at the bouncy command and give it a port to listen on:

bouncy routes.json 80

Super easy! Check out the code on github or with npm do:

npm install bouncy

to install the library or

npm install -g bouncy

to install the command-line tool.

more
git clone http://substack.net/blog.git