title: Dynamic routing based on file system directory search
body: <p>I want to route to an HTML page without having '.html' in the URL.  I am trying to do this by creating a custom router that looks through a directory and checks to see if there is a file with the extension '.html', if there is it will route to that page.</p>
  
  <p>I also need to allow the router to fall through the <code>'/api'</code> route if the URL contains '/api'.  Essentially I want to allow users to get HTML files without having to type the file extension and keep all other routing intact.</p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var fs = require('fs');
  var router = express.Router();
  var app = express();
  
  router.route('/:id')
      .get(function(req, res) {
          fs.readdir('public/', function(err, items) {
              for (var i=0; i&lt;items.length; i++) {
                if (req.params.id == path.basename(items[i])) {
                  app.get(function(req, res) {
                      res.render(items[i]);
                  });
              }
            }
          });
      });
  
  router.route('/api')
    .get(function (req, res) { ... })
    .post(function (req, res) { ... });
  
  app.use('/', router);
  </code></pre>
  
  <p>I also tried using <code>express.static</code> but its not working either.</p>
  
  <p><code>fs.readdir('public/', function(err, items) {
      for (var i=0; i&lt;items.length; i++) {
          if (path.extname(items[i]) == '.html') {
              app.use('/' + path.basename(items[i], '.html'), express.static(items[i]));
          }
      }
  });</code></p>