node-http-proxy
node-http-proxy copied to clipboard
How to proxy request to its actual host?
I am setting basic proxy server one which logs request headers and foward it to actual host and then show actual response on webpage. However following code is not showing actual response. If I remove code inside responseHandler, then there is nothing shown on the webpage and it keeps loading. How to handle this?
var http = require('http'),
httpProxy = require('http-proxy');
httpProxy.createServer({
for:'http://localhost:9003'
}).listen(8000);
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9003);