title: How to use a middleware router for a sub path in express nodejs
body: <p>I would like to sue a middleware just for the /doc path so it can serve satic file and have a basic auth.</p>
  
  <p>But when i try to get /doc i have a cannot get /doc error.</p>
  
  <p>Does anyone have any idea ?</p>
  
  <pre><code>var app = express();
  app.use(bodyParser.urlencoded({ extended: true }));    // parse application/x-www-form-urlencoded
  app.use(bodyParser.json())  ;  // parse application/json
  app.use(functio    //app.use('/doc', express.static('./doc'));n(req, res, next) {
      res.header("X-powered-by", "NodeJs");
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization");
      next();
  });
  app.use(function(req, res, next) {
      console.log(' - ',req.originalUrl);
      next();
  });
  
  var router = express.Router();
  
  router.use(express.basicAuth('testUser', 'testPass'));
  
  router.get('/doc', function(req, res, next) {
      console.log("inside doc");
      express.static('./doc');
      next();
  });
  
  app.use('/conf',require('./v1/data_config'));
  </code></pre>
  
  <p>thanks and regard</p>