Wednesday, 10 May 2017

Node.js http-proxy traffic monitoring

I'm trying to set up a proxy server that should return the http requests from any page that I'm accessing.

Basically, if I navigate to www.google.com then I'm expecting to get the following requests:

enter image description here

Is this achievable using node-http-proxy module?

I've tried the following code, but can't figure out how to get the requests..

var http = require('http'),  
    httpProxy = require('http-proxy');

//
// Create a proxy server with custom application logic
//
httpProxy.createServer(function (req, res, proxy) {  
  //
  // Put your custom server logic here
  //

  proxy.proxyRequest(req, res, {
    host: 'localhost',
    port: 9000
  });
}).listen(8000);

http.createServer(function (req, res) {  
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write('request successfully proxied: ' + req.url +'\n' + JSON.stringify(req.headers, true, 2));
  res.end();
}).listen(9000);



via Valip

No comments:

Post a Comment