title: Express.js middleware branching or multiple app.routes middlewares
body: <p>We are creating a separate API app, but are forced to make it part of the existing express.js main app.</p>
  
  <p>My question is, how to put API authentication in a proper place. I want to make it a middleware, and behind which would be the <code>app.routes</code> middleware to handle the API routes.</p>
  
  <p>Is it possible to either:</p>
  
  <ul>
  <li>Branch off the main middleware stack after determining the subdomain is <code>['api']</code>?</li>
  </ul>
  
  <p>or</p>
  
  <ul>
  <li>Put the authentication middleware and API <code>app.routes</code> middleware in front of the main <code>app.routes</code> middleware? (in effect having two layers of <code>app.routes</code> middleware)</li>
  </ul>
  
  <p>edit:</p>
  
  <p>Also, suppose I go with the second option, is it possible to expose the two middlewares (auth + api <code>app.routes</code>) as a single middleware in the global list?</p>