Created
May 5, 2014 09:17
-
-
Save mdijoux/5fd76e092c85d18aa0e4 to your computer and use it in GitHub Desktop.
Express view rendering based on extension
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 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