Skip to content

Instantly share code, notes, and snippets.

@veltman
Created August 5, 2014 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veltman/920716d8bd469ca277d4 to your computer and use it in GitHub Desktop.
Save veltman/920716d8bd469ca277d4 to your computer and use it in GitHub Desktop.
var express = require('express');
var app = express();
var fs = require('fs');
app.use(function(req, res, next) {
if (req.url.match(/^\/?[^/]+\/?$/)) {
if (req.url.match(/[.][0-9a-z]+$/i)) {
next();
} else {
if (!req.url.match(/\/$/)) {
req.url = req.url+"/";
}
fs.stat(req.url.replace(/^\//,"")+"index.html",function(err,st) {
if (err) res.redirect(req.url+"live_files/index.html");
else res.redirect(req.url+"index.html");
});
}
} else {
next();
}
});
app.use(express.static(__dirname));
app.listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment