Created
January 18, 2012 20:28
-
-
Save apeckham/1635337 to your computer and use it in GitHub Desktop.
node duplicating proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "urban-proxy", | |
"version": "0.0.1", | |
"dependencies": { | |
"http-proxy": "0.7.6" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: node web.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SO URBAN