Skip to content

Instantly share code, notes, and snippets.

@mdijoux
Created May 5, 2014 09:17
Show Gist options
  • Save mdijoux/5fd76e092c85d18aa0e4 to your computer and use it in GitHub Desktop.
Save mdijoux/5fd76e092c85d18aa0e4 to your computer and use it in GitHub Desktop.
Express view rendering based on extension
var App = express();
App.engine('html', require('ejs').renderFile);
App.set('views', '/');
App.set('view engine', 'html');
App.use(function(req, res, next){
res.locals.title = 'Test';
next();
});
App.all(/.*\.html$/, function(req, res, next){
console.log(req.url);
if (path.existsSync(req.url)) {
res.render(req.url.substring(1));
} else {
next();
}
});
App.use(express.static('/'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment