node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

How to proxy request to its actual host?

Open shashwat001 opened this issue 3 years ago • 0 comments

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);

shashwat001 avatar Jun 27 '21 12:06 shashwat001