title: NodeJS + Express: How to secure a URL
body: <p>I am using latest versions of NodeJS and ExpressJS (for MVC).</p>
  
  <p>I usually configure my rest paths like this, for example:</p>
  
  <pre><code>app.get('/archive', routes.archive);  
  </code></pre>
  
  <p>Now i want my <code>/admin/*</code> set of URLs to be secured, I mean I need just simple authentication, it's just a draft. </p>
  
  <p>When a user tries to access, for example, <code>/admin/posts</code>, before sending him the corresponding view and data, I check for a req.session.authenticated. If it's not defined, I redirect to the login page.</p>
  
  <p>Login page has a simple validation form, and a sign-in controller method: if user does send "right user" and "right password" I set the session variable and he's authenticated.</p>
  
  <p>What I find difficult, or I don't understand, is how to actually make the <strong>"filter"</strong> code, I mean, the auth check, before every /admin/* path call. </p>
  
  <p>Does this have something to do with "middleware" express functions? </p>
  
  <p>Thank you</p>