title: Cannot use basic authentication while serving static files using express
body: <p>Using the Express framework for node.js, I'm trying to serve up static files contained in a directory while also putting basic authentication on it. When I do so, I am prompted for the username and password (as expected), but after I correctly enter them, I'm given a 404. If I remove the authentication check and serve up the same directory, I actually get the pages contained within it.</p>
  
  <p>Here's a quick server I whipped up as a proof-of-concept:</p>
  
  <pre><code>var express = require('express');
  
  var app = express();
  
  var auth = express.basicAuth(function(user,pass) {
    return 'user' === user &amp;&amp; 'pass' === pass;
  });
  
  app.use('/admin', auth, express.static(__dirname + '/admin'));
  app.use('/adminNoAuth', express.static(__dirname + '/admin'));
  
  app.listen(8082);
  </code></pre>
  
  <p>When I hit <code>localhost:8082/admin</code> I get the username/password, then a 404. When I hit <code>localhost:8082/adminNoAuth</code> it serves up the page.</p>
  
  <p>I'm using Express 3.4.7 and node.js 0.10.22.</p>