title: Node Express: res.redirect broken when using proxy
body: <p>I have a node express app running behind a proxy, using Apache ProxyPass (configured in httpd.conf):</p>
  
  <pre><code>ProxyPass /nodeapp http://localhost:9009
  </code></pre>
  
  <p>My application uses Passport to authenticate users, so when I access the base path I should be redirected to the login page:</p>
  
  <p>-- old redirect: <a href="http://example.com:9009" rel="nofollow">http://example.com:9009</a> --> <a href="http://example.com:9009/login" rel="nofollow">http://example.com:9009/login</a></p>
  
  <p>-- new redirect: <a href="http://example.com/nodeapp" rel="nofollow">http://example.com/nodeapp</a> --> <a href="http://example.com/nodeapp/login" rel="nofollow">http://example.com/nodeapp/login</a> </p>
  
  <p>Unfortunately, the redirect is not working:</p>
  
  <p>-- broken redirect: <a href="http://example.com/nodeapp" rel="nofollow">http://example.com/nodeapp</a> --> <a href="http://example.com/login" rel="nofollow">http://example.com/login</a></p>
  
  <p>I have tried to enable proxy configuration in express, but this made no difference:</p>
  
  <pre><code> app.enable('trust proxy');
  </code></pre>
  
  <p>** EDIT: **
  As suggested by Ethan in the comments below, I can hardcode all my paths to suit the new environment, however this will then break the paths when running on my local machine at root ('/'). </p>
  
  <p>I looking for a more centralised solution which can adapt to different runtime environments if possible?</p>