-
-
Save coderarity/3965464 to your computer and use it in GitHub Desktop.
Proxt
This file contains 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 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