Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created January 18, 2012 20:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeckham/1635337 to your computer and use it in GitHub Desktop.
Save apeckham/1635337 to your computer and use it in GitHub Desktop.
node duplicating proxy
node_modules
{
"name": "urban-proxy",
"version": "0.0.1",
"dependencies": {
"http-proxy": "0.7.6"
}
}
web: node web.js
var http = require('http'), httpProxy = require('http-proxy'), util = require('util');
var heroku = {host: 'proxy.heroku.com', port: 80};
var noResponse = {writeHead: function() {}, end: function() {}};
var percentage = parseInt(process.env.PERCENTAGE || 0);
httpProxy.createServer(function(req, res, proxy) {
req.headers.host = "urban-production-192.heroku.com";
delete req.headers['accept-encoding'];
proxy.proxyRequest(req, res, heroku);
if (percentage > Math.random() * 100) {
req.headers.host = "urban-postgres.heroku.com";
proxy.proxyRequest(req, noResponse, heroku);
}
}).listen(process.env.PORT || 80);
@jamiew
Copy link

jamiew commented Jan 18, 2012

SO URBAN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment