Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve index.html pages from subdirectories #26

Open
skerit opened this issue Jan 10, 2017 · 1 comment
Open

Serve index.html pages from subdirectories #26

skerit opened this issue Jan 10, 2017 · 1 comment

Comments

@skerit
Copy link

skerit commented Jan 10, 2017

Currently this option is only available on the 'home' path, it would be quite useful to have this in subdirectories, too.

@finwo
Copy link

finwo commented Jun 7, 2017

While certainly not a permanent fix, I managed to work around this with the following code after creating the router.

  // Register new 405 handler
  router.__405 = router._405;
  router._405  = function( req, res, route ) {
    var files = config.http.default_home.map(function(filename) {
      return path.join( route, filename );
    }).filter(function(shortname) {
      try {
        var stat = fs.statSync(path.join(config.http.static_route, shortname));
        return stat.isFile();
      } catch(e) {
        return false;
      }
    });
    
    if(files.length) {
      return router.static(files.shift(), req, res);
    }
    
    return router.__405(req, res, route);
  };

Keep in mind that I've fetched the config.http array from my own config structure. You will need to supply your own configuration to make this work within your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants