When modifying a node-http-proxy example...
The Issue: When manually changing the req.headers.host
to a remote host ('example.com'), the url in the the browser is not changing.
Note: I thought this was working, however when using google.com as my example, it turned out google was detecting the proxy and changing the host.
Question: Is there a way to change the url in the browser to a remote host (ie. example.com), everytime? Thanks!
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('../../lib/node-http-proxy');
//
// Http Server with proxyRequest Handler and Latency
//
var proxy = new httpProxy.RoutingProxy();
http.createServer(function (req, res) {
req.headers.host = 'example.com'; // manually setting example.com
var buffer = httpProxy.buffer(req);
setTimeout(function () {
proxy.proxyRequest(req, res, {
port: 80,
host: 'example.com',
buffer: buffer
});
}, 200);
}).listen(8004);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8004 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
A few solutions that will do this are: