title: Express static serving wrong path
body: <p>I am messing around with express.js and have built some basic functionality but am having issues with express static serving from the wrong place if the URL is longer than one directory from root. See the examples below. </p>
  
  <p>I am using the normal documented approach to using static. </p>
  
  <pre><code>app.use(express.static(__dirname + '/public'));
  </code></pre>
  
  <p>And have set up a couple of routes. eg. </p>
  
  <pre><code>app.get('/signup', function(req, res) {
      res.render('signup.ejs');
  });
  </code></pre>
  
  <p>With a 404 catch at the end of the chain. </p>
  
  <pre><code>app.get('*', function(req, res){
      res.status(404).render('404');
  });
  </code></pre>
  
  <p>If I hit page such as <code>localhost:3000</code> or <code>localhost:3000/login</code> which are defined routes, all is well. Even if I hit an undefined route of <code>localhost:3000/foo</code>, I get the 404 rendered correctly with all images present. </p>
  
  <p>However if I go one further and do something like <code>localhost:3000/login/foo</code> all the images are missing and I will get an error in the browsers console with the following address. </p>
  
  <p><code>http://localhost:3000/login/img/site-brand.png</code></p>
  
  <p>This happens the same on routes defined with more than one directory too.</p>
  
  <p>I interpreted the docs on the express website that regardless of what was calling for the static image it would be served from the public directory in root, which contains a js, img, and css directories. </p>
  
  <p>My questions are, what have I misinterpreted? and how do I get express to always serve relative to root? </p>