Created
November 30, 2013 14:21
-
-
Save A/7719691 to your computer and use it in GitHub Desktop.
Routes also have the .param method to allow for easier resource loading in this case we will make sure all our routes load the post
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
// vendor | |
var express = require('express'); | |
var router = new express.Router(); | |
// routes also have the .param method to allow for easier resource loading | |
// in this case we will make sure all our routes load the post | |
router.param('post_id', function(req, res, next, post_id) { | |
// simulate loading a post | |
setTimeout(function() { | |
req.post = { name: 'foo' }; | |
next(); | |
}, 1000); | |
}); | |
router.get('/:post_id', function(req, res, next) { | |
res.send(req.post.name + '\n'); | |
}); | |
router.post('/:post_id/comment', function(req, res, next) { | |
// we could add the comment to req.post here | |
res.send('\\o/\n'); | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment