title: Express.js 4 - use middleware for authentication before static files
body: <p>In my <code>express</code> app I've set static files to be served from the <code>/public</code> directory with this line:</p>
  
  <pre><code>app.use(express.static(__dirname + '/public'));
  </code></pre>
  
  <p>Now I need to add a middleware for authentication before serving the static content and if the user is not authenticated to be redirected to a route for authentication (e.g., <code>/login</code>).<br />
  I'm not really sure how I have to do it. Any ideas?</p>