-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lifecycle hooks on routes #2566
Comments
I've long wanted to change the ext functionality to be per:
But I am worried about the overhead of checking for all those. Right now when nothing is set it is a simple null check at each ext point. For this to work I will need to change the lifecycle array generation to actually build the array per route as well as rebuild it when extensions are added later after route config. Maybe for 9.0. |
This would be wonderful. @hueniverse are you worried about overhead at the time of server start, or throughout the course of a single request? |
Only care about hot code. Executing the request lifecycle is hot. |
Looking forward to this feature; here's my use case... I'm using Hapi as an API Gateway. I have four clients accessing this API, each has its own set of routes. One of the clients is an Ember app which requires the API response to conform to the JSON API spec. I'm using a Hapi plugin (inspired by hapi-json-api.js) to handle some of the boilerplate code required to munge the response into something JSON API compliant. The plugin uses Hapi lifecycle hoks which unfortunately has the effect of making all my routes conform to JSON API. |
What would the interface look like for adding extensions to one or more routes? I got ideas but want to see what other people think. |
I see three options, some of which could probably work in tandem.
I think I favor the first and third options, possibly in tandem, since it seems like core should keep server extensions programmatic rather than configured. A plugin (i.e. mrhorse) could implement something like the second option. One thing I don't like about option three on its own is that it requires that the route have an id. If |
I do like 1 although 2 would make it easier if adding to multiple routes, maybe a tag system can help where you tag routes with keywords and select on them to add extensions to all of them |
If collections of routes were selectable by tag, that would be neat. Most important is that extensions can be added to routes programmatically and arbitrarily (not requiring a tag or id). I do like the syntax of 2 since it's descriptive, but I don't think it's flexible enough. We have an issue in mrhorse to support that type of route configuration (mark-bradshaw/mrhorse#23), so I can nearly guarantee that there will be a tool in the hapi ecosystem similar to the second option if hapi doesn't implement it. |
I also prefer version 2. It would be nice to also be able to have the same format globally, much like we inherit properties from the server currently. |
For now I added support for option 2 and a new What is missing is being able to define a route selection criteria and apply an extension to that, like an extension for all GET requests. But I need to think about it some more so this will do for now. |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
What would you think of allowing the lifecycle hooks (all but onRequest obviously) to be set per route ?
The filtering I have to do to match routes in those functions just pollutes the readability of it.
Having global hooks when they're not used as such probably also is a tiny waste of resource however minor.
The text was updated successfully, but these errors were encountered: