title: Excluding routes from authentication express site
body: <p>I'm creating an app using node, express, and have a passport authorization middleware implemented for all routes-. I am following a highly modular approach to build my app. I try to exclude specific APIs from authentication when I include them above the authorization middleware. But when I include <code>app.use('/', require('./api/search/index'));</code> above the authorization middleware, APIs beneath stop working.
  Criticism and suggestion are all welcome for this approach and what can I do to resolve this problem.
  I don't want to include route middleware in each route like this</p>
  
  <pre><code>route.get('/example', auth.middleware(), function (req, res) {
  })
  </code></pre>
  
  <p>Below is my app approach with single authorization middleware for all routes</p>
  
  <pre><code>var express = require('express');
  var bodyParser = require('body-parser');
  var app = express();
  var auth = require("./auth.js")();
  
  app.use(auth.initialize());
  
  //Excluding the search API from Authentication,
  app.use('/', require('./api/search/index'));
  
  //Middleware for all APIs and require Auth headers for authrization access
  app.use(auth.authenticate(), function (req, res, next) {
      if (req.headers.authorization &amp;&amp; req.user) {
          var parted = req.headers.authorization.split(' ');
          if (parted.length === 2) {
              console.log(req.user);
              next();
          } else {
              return res.status(403).send({
                  success: false,
                  msg: 'Unauthorized.'
              });
          }
      } else {
          return res.status(503).send({
              success: false,
              msg: 'Bad Request'
          });
      }
  });
  
  //Join routers
  app.use('/', require('./api/users/index'));
  app.use('/', require('./api/product/index'))
  app.use('/', require('./api/company/index'))
  </code></pre>