Created
August 5, 2014 16:15
-
-
Save veltman/920716d8bd469ca277d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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