Created
September 28, 2011 03:20
-
-
Save ryanrolds/1246910 to your computer and use it in GitHub Desktop.
Tried something tricky, didn't work
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'); | |
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