Sha256: 3d6a9765592a39fbd452eb66b55d9b2847c43edb520c21fb5f8404b7c36aa4e2

Contents?: true

Size: 754 Bytes

Versions: 17

Compression:

Stored size: 754 Bytes

Contents

var httpProxy = require('../../lib/node-http-proxy');
//
// A simple round-robin load balancing strategy.
// 
// First, list the servers you want to use in your rotation.
//
var addresses = [
  {
    host: 'ws1.0.0.0',
    port: 80
  },
  {
    host: 'ws2.0.0.0',
    port: 80
  }
];

httpProxy.createServer(function (req, res, proxy) {
  //
  // On each request, get the first location from the list...
  //
  var target = addresses.shift();

  //
  // ...then proxy to the server whose 'turn' it is...
  //
  console.log('balancing request to: ', target);
  proxy.proxyRequest(req, res, target);

  //
  // ...and then the server you just used becomes the last item in the list.
  //
  addresses.push(target);
}).listen(8000);

// Rinse; repeat; enjoy.

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/http-proxy/examples/balancer/simple-balancer.js