title: Node express routing sendfile fails depending on file location
body: <p>I have a directory structure for a restful express service + Backbone client with <strong>pushState</strong> enabled like this (client code in <code>public/</code>)</p>
  
  <pre><code>app.js
  lib/routes.js
  -- public/
     -- index.html
  </code></pre>
  
  <p>I set up <code>/public</code> to be a static directory in <code>app.configure</code>:</p>
  
  <pre><code>app.use(express.static(__dirname + '/public'));
  </code></pre>
  
  <p>This already works off the bat if the index is visited first.</p>
  
  <p>Then when I directly visit a route other than homepage I ensure to redirect to the <code>index.html</code>. This works perfectly fine in <code>app.js</code>, <strong>but if I try and put this in <code>lib/routes.js</code> I get a Forbidden error</strong>:</p>
  
  <p>From <code>app.js</code> works fine:</p>
  
  <pre><code>app.get('*', function(req, res) {
      res.sendfile(__dirname + '/public/index.html');
  });
  </code></pre>
  
  <p>From <code>lib/routes.js</code>:</p>
  
  <pre><code>res.sendfile(__dirname + '../public/index.html');
  </code></pre>
  
  <p>Gives me:</p>
  
  <pre><code>Error: Forbidden
          at SendStream.error (/Users/*****/Sites/myproject/node_modules/express/node_modules/send/lib/send.js:145:16)
          at SendStream.pipe (/Users/*****/Sites/myproject/node_modules/express/node_modules/send/lib/send.js:307:39)
          at ServerResponse.res.sendfile (/Users/*****/Sites/myproject/node_modules/express/lib/response.js:345:8)
          at /Users/*****/Sites/myproject/lib/routes.js:8:7
          at callbacks (/Users/*****/Sites/myproject/node_modules/express/lib/router/index.js:164:37)
          at param (/Users/*****/Sites/myproject/node_modules/express/lib/router/index.js:138:11)
          at pass (/Users/*****/Sites/myproject/node_modules/express/lib/router/index.js:145:5)
          at Router._dispatch (/Users/*****/Sites/myproject/node_modules/express/lib/router/index.js:173:5)
          at Object.router (/Users/*****/Sites/myproject/node_modules/express/lib/router/index.js:33:10)
          at next (/Users/*****/Sites/myproject/node_modules/express/node_modules/connect/lib/proto.js:193:15)
  </code></pre>
  
  <p>If I simply try:</p>
  
  <pre><code>res.sendfile('/public/index.html');
  </code></pre>
  
  <p>It can't find the file and I get:</p>
  
  <pre><code>Error: ENOENT, stat '/public/index.html'
  </code></pre>
  
  <p>To summarise how can I use <code>sendFile</code> and pass in <code>public/index.html</code> from <code>lib/routes.js</code> without getting a Forbidden error?</p>