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:
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);
UPDATE:
I configured your browser to use my proxy server, and changed the code as follows:
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create a proxy server with custom application logic
//
var proxy = httpProxy.createServer(function (req, res, proxy) {
//
// Put your custom server logic here
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9000
});
})
proxy.listen(8000);
proxy.on('proxyReq', function(proxyReq, req, res, options) {
console.log(req.url);
console.log(proxyReq.url);
});
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);
But there are no logs in the console when I'm accessing different websites