Created
February 29, 2012 23:20
-
-
Save devinrhode2/1945313 to your computer and use it in GitHub Desktop.
File system based routing within express
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
In express app.js, remove all app.get routings, and put this: | |
app.get('*', function(req, res) { | |
file = req.params[0].substr(1, req.params[0].length); | |
console.log('requesting: ' + file); | |
res.render(file, {locals: { | |
request: req, | |
params: req.query | |
}}); //in your .jade file, variables request and params are available. | |
}) | |
//In your view directory, create a new file, .html, .jade with the jade module, .ejs with the ejs module, and navigate to it in your web browser. This should 'just work'. Creating /newfolder/index.jade, will, you guessed it, be the page for /newfolder/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment