Created
December 17, 2016 03:15
-
-
Save anonymous/c7bf36c2cbf2409ae9be8e651e386670 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
const userRouter = new Router() | |
.get('/', users.show) | |
.use(userIsAdminMiddleware) | |
.put('/', users.update) | |
.del('/', users.destroy) | |
app | |
.use('/users', new Router() | |
.use('/:username', userRouter) | |
.get('/', users.list) | |
.post('/', users.create) | |
) | |
.use('/account', [ | |
(req, res, next) => { | |
req.params.username = req.user.username | |
next() | |
}, | |
userRouter | |
]) | |
// versus | |
app | |
.get('/users/:username', users.show) | |
.put('/users/:username', users.update) | |
.del('/users/:username', users.destroy) | |
.get('/users', users.list) | |
.post('/users', users.create) | |
// woooooot need to duplicate a bunch of routes | |
.use('/account', () => (req, res, next) => { | |
req.params.username = req.user.username | |
next() | |
}) | |
// woot, need to duplicate a bunch of stuff :( | |
.get('/account', users.show) | |
.put('/account', users.update) | |
.del('/account', users.destroy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.use('/account', () => (req, res, next) => {
should be.use('/account', (req, res, next) => {
and there are probably other typos