Skip to content

Instantly share code, notes, and snippets.

@ryanrolds
Created September 28, 2011 03:20
Show Gist options
  • Save ryanrolds/1246910 to your computer and use it in GitHub Desktop.
Save ryanrolds/1246910 to your computer and use it in GitHub Desktop.
Tried something tricky, didn't work
var http = require('http');
var httpProxy = require('http-proxy');
var responseWrap = function (res) {
var write = res.write;
res.write = function() {
// Do stuff
write.apply(this,arguments);
}
return res;
);
httpProxy.createServer(function (req, res, proxy) {
//this api is why I'm trying to do it this way.
proxy.proxyRequest(req, responseWrap(res), {
host: "localhost",
port: 9000
});
}).listen(8000);
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied!' + '\n' +
JSON.stringify(req.headers, true, 2) + '\n' +
JSON.stringify(req.socket.remoteAddress, true, 2) + '\n' +
JSON.stringify(req.url) + '\n' +
""
);
res.end();
}).listen(9000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment