Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created March 14, 2011 20:15
Show Gist options
  • Select an option

  • Save indexzero/869781 to your computer and use it in GitHub Desktop.

Select an option

Save indexzero/869781 to your computer and use it in GitHub Desktop.

Revisions

  1. indexzero revised this gist May 1, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion round-robin-proxy.js
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ httpProxy.createServer(function (req, res, proxy) {
    // Remark: You may want to do host header checking here
    // by looking at req.headers.host.
    //
    proxy.proxyRequest(req, res, target.port, target.host);
    proxy.proxyRequest(req, res, target);

    //
    // Push the location to the end of the 'queue'.
  2. indexzero created this gist Mar 14, 2011.
    35 changes: 35 additions & 0 deletions round-robin-proxy.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    var httpProxy = require('http-proxy');

    //
    // Addresses to use in the round robin proxy
    //
    var addresses = [
    {
    host: 'ws1.0.0.0',
    port: 80
    },
    {
    host: 'ws2.0.0.0',
    port: 80
    }
    ];

    httpProxy.createServer(function (req, res, proxy) {
    //
    // Get the first location off of the 'queue'.
    //
    var target = addresses.shift();

    //
    // Proxy to the specified location
    //
    // Remark: You may want to do host header checking here
    // by looking at req.headers.host.
    //
    proxy.proxyRequest(req, res, target.port, target.host);

    //
    // Push the location to the end of the 'queue'.
    //
    addresses.push(target);
    });