Using Node.js to redirect and proxy normal HTTP+WebSocket traffics based on hostnames

Usually I used to use a single server to host several developing or experimental projects. Thus I need a quick solution to forward different request to these services. I had tried to use nginx before. But now I have a easier way to do so.

  1. require modules

  2. config proxy(forward) and redirect mappings (hostname based)

    var proxyOptions = {
    router: {
    "api.testAppX.com" : 'localhost:2041',
    "dev.api.testAppX.com" : 'localhost:2042',
    "www.testAppY.com" : 'localhost:10520',
    "test.oldApps.com" : 'localhost:10520',
    'bc.ryanwu.co' : 'localhost:8888'
    }
    },
    redirectOptions = {
    'olddomain.com' : 'http://newdomain.com/',
    'www.olddomain.com' : 'http://newdomain.com/',
    'blog.olddomain.com' : 'http://newdomain.com/blog/'
    };