-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Feat: onApplicationReady Hook #13806
Comments
+1 support |
I'm not sure about the naming and the role of that hook. I'd need to think more about it. But I can say that maybe we need a more specific name because 'ready' can be interpreted in several ways You can supply a callback already to |
@micalevisk Maybe something like onApplicationInit |
'init' would be confusing because we have |
What about using https://docs.nestjs.com/techniques/events and then await app.listen(...);
await app.get(EventEmitter2).emit(...); Done(?) This gives you full control too |
@kamilmysliwiec I personally already use this approach. It just feels like this functionality should be available out of the box with the rest of the hooks and have similar usage. Without this hook, lifecycle hooks feel incomplete. |
The thing is, |
Yeah, I didn't take those things into account when I came up with the hook name. Naming is not my strong point :) There's a lot to think about here. You guys know better anyway. |
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
There are a lot of potential tasks that can be done successfully only after the start of an application (when the app is ready to handle connections).
The
onApplicationBootstrap
triggers beforeawait app.listen()
, so it can't be used for such tasks (correct me if I'm wrong).Describe the solution you'd like
Although this can be easily implemented using events, another good option would be introducing a new hook that triggers after
await app.listen()
.Teachability, documentation, adoption, migration strategy
The hook's name can be
onApplicationReady
oronApplicationStart
. The usage of the hook will be pretty similar to the other hooks:What is the motivation / use case for changing the behavior?
One of the use cases could be webhook subscriptions. When I subscribe to webhooks, the publisher sends me a POST request to verify my webhook callback. It is safer to perform this task after the application is ready to listen for connections.
The text was updated successfully, but these errors were encountered: