Closed girishla closed 8 years ago
I achieve this using a plugin called mrhorse. It allows you to attach "policies" onto a route, which is usually a pre- or post-handler hook. In the most recent version of hapi there are actually per-route lifecycle hooks that are very clean and performant. I'd suggest upgrading to the most recent version of hapi if you haven't already. If you can't upgrade (e.g. if you're stuck on node v 0.10) then mrhorse is the way to go.
Edit
I'll add, I've used bedwetter and mrhorse for an identical use-case to you, and it has worked great. At the top of each post-handler policy you may need to check if request.response.isBoom
since errors from the handler are passed-along to subsequent lifecycle hooks.
mrhorse it is then. Exactly what I was looking for. Thanks,
I need to emit a socketIO event when certain bedwetter handler routes finish successfully(no Boom errors). Bedwetter registers itself as a handler and I can't seem to find a nice way to do a post-handler action.
What would be nice is if bedwetter provides some sort of a post handler hook or alternatively allow bedwetter to be executed as one of the pre-handler functions.
For the time being I can perhaps use the 'onPostHandler' extension point and look for successful routes but that doesn't seem like the best solution. Is there a better way ?