mercredi 1 avril 2015

Using controller's method as both endpoint and middleware

Here are 2 simple scenarios:



  1. Get user with id and return

  2. Get user with id, do some other stuff, and then return


I want to implement scenario 2 as



router.post('/api/users/:id/someStuff', controller.getUser, controller.doStuff)


But scenario 1 should be implemented as



router.post('/api/users/:id/someStuff', controller.getUser)


Basically, controller.getUser is both a middleware and an endpoint. How do I accomplish this? If I use res.son() inside getUser and later on reuse it inside doStuff, then I get an error.


Aucun commentaire:

Enregistrer un commentaire