title: Express middleware not being called
body: <p>I'm using express router to build the routes in my application and I'm trying to apply custom middleware to each route so the middleware will only be called when urls are hit for that specific router. Here's my code:</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const authentication = require('./helpers/authentication');
  
  const registerController = (app, path, router, middleware) =&gt; {
    middleware.forEach((routerMiddleware) =&gt; {
      router.use(routerMiddleware);
    });
    app.use(path, router);
  };
  
  const testMiddleware = (request, response, next) =&gt; {
    console.log(request.originalUrl);
    next();
  };
  
  module.exports = {
    init: (app) =&gt; {
      registerController(app, '/auth', require('./authenticationController'), [testMiddleware]);
      registerController(app, '/customer', require('./customerController'), [authentication, testMiddleware]);
      registerController(app, '/filter', require('./filterController'), [authentication, testMiddleware]);
      registerController(app, '/', require('./homeController'), [testMiddleware]);
      registerController(app, '/inventory', require('./inventoryController'), [authentication, testMiddleware]);
      registerController(app, '/settings', require('./settingsController'), [authentication, testMiddleware]);
    }
  };
  </code></pre>
  
  <p>I've built the registerController method so I can assign middleware in different configurations to the different routers. Each require statement that pulls in a file name xxxController is returning a router like this:</p>
  
  <pre><code>const router = require('express').Router();
  const fs = require('fs');
  
  router.get('/', (request, response) =&gt; {
    const file = fs.readFileSync(__dirname + '/../index.html', "utf8");
    response.send(file);
  });
  
  module.exports = router;
  </code></pre>
  
  <p>I added the test middleware to see if the simplest middleware would work, but it's not being called.  What am I doing wrong here?</p>