Last active
August 29, 2015 14:02
-
-
Save Janpot/9947ded680ce1964bb44 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 userRouter = express.Router(), | |
projectsRouter = express.Router(); | |
userRouter.use('/:userId', function (req, res, next) { | |
req.user = fetchAndValidate(req.param('userId')); | |
next(); | |
}); | |
projectsRouter.use('/', function (req, res, next) { | |
res.send(fetchProjects(req.user)); | |
}); | |
projectsRouter.use('/:projectId', function (req, res, next) { | |
req.project = fetchAndValidate(req.user, req.param('projectId')); | |
next(); | |
}); | |
projectsRouter.get('/:projectId', function (req, res, next) { | |
res.send(req.project); | |
}); | |
projectsRouter.put('/:projectId', function (req, res, next) { | |
updateProject(req.user, req.project, req.body); | |
res.send(req.project); | |
}); | |
userRouter.use('/:userId/projects', projectsRouter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment