Skip to content

Instantly share code, notes, and snippets.

@coderarity
Forked from hackable/gist:3965462
Created October 27, 2012 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderarity/3965464 to your computer and use it in GitHub Desktop.
Save coderarity/3965464 to your computer and use it in GitHub Desktop.
Proxt
var httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
var buffer = httpProxy.buffer(req);
middleware(res, function() {
console.log("The request was proxied");
});
proxy.on('proxyError', function () {
proxy.proxyRequest(req, res, {
host: 'nextHost.com',
port: 80,
buffer: buffer
});
proxy.proxyRequest(req, res, {
host: 'google.com',
port: 80,
buffer: buffer
});
}).listen(9091);
function middleware(res, callback) {
var _end = res.end;
res.end = function(data) {
_end.call(res, data);
if (callback) callback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment