title: Forward every request with node-http-proxy
body: <p>I'm trying to setup a node-http-proxy that just forwards requests. 
  In the end this proxy should inject javascript in every website I visit through the browser..</p>
  
  <p>Right now, most pages are forwarded and displayed correctly, but some, like <a href="http://posterkoenig.ch" rel="nofollow noreferrer">posterkoenig.ch</a> or  <a href="http://verkehrsclub.ch" rel="nofollow noreferrer">verkehrsclub.ch</a> are returning either a blank page or there is an error on the page.  Both sites work well without the proxy in place. What do I have to change, or what am I  missing that gets not forwarded correctly?</p>
  
  <p>Im very new to nodejs and not even completely sure if my approach should work or not.</p>
  
  <p>Here is what I've got so far:</p>
  
  <pre><code>var httpProxy = require('http-proxy');
  var url = require('url');
  
  httpProxy.createServer(function(req, res, proxy) {
  
    var urlObj = url.parse(req.url);
  
    proxy.proxyRequest(req, res, {
      host: urlObj.host,
      port: 80,
      changeOrigin: true,
      enable : { xforward: true }
    });
  }).listen(9000, function () {
    console.log("Waiting for requests...");
  });
  </code></pre>
  
  <hr>
  
  <h3>Update</h3>
  
  <p>As suggested by @robertklep I removed <code>changeOrigin</code> and redefined <code>req.headers.host</code> and also <code>req.headers.url</code></p>
  
  <p><em>posterkoenig.ch</em>:</p>
  
  <p>Now throws: </p>
  
  <pre><code>An error has occurred: 
  {"code":"ENOTFOUND","errno":"ENOTFOUND","syscall":"getaddrinfo"}
  </code></pre>
  
  <p><em>verkehrsclub.ch</em>:</p>
  
  <p>The frontpage works now but subpages still throw a error on the page.</p>
  
  <pre><code>var httpProxy = require('http-proxy');
  var url = require('url');
  
  httpProxy.createServer(function(req, res, proxy) {
  
    var urlObj = url.parse(req.url);
  
    req.headers['host'] = urlObj.host;
    req.headers['url'] = urlObj.href;
  
    proxy.proxyRequest(req, res, {
      host: urlObj.host,
      port: 80,
      enable : { xforward: true }
    });
  }).listen(9000, function () {
    console.log("Waiting for requests...");
  });
  </code></pre>