Application Startup Configuration
When the application starts up, we often need to set up some initialization logic. The application bootstraps with those specific configurations. It is in a healthy state and be able to take external service requests after those configurations successfully applied. Otherwise, it failed.
The framework provides a unified entry file (app.js
) for boot process customization. This file need returns a Boot class. We can define the initialization process in the startup application by defining the lifecycle method in the Boot class.
The framework has provided you several functions to handle during the whole life cycle:
configWillLoad
: All the config files are ready to load, so this is the LAST chance to modify them.configDidLoad
: When all the config files have been loaded.didLoad
: When all the files have been loaded.willReady
: When all the plug-ins are ready.didReady
: When all the workers are ready.serverDidReady
: When the server is ready.beforeClose
: Before the application is closed.
We can defined Boot class in app.js
. Below we take a few examples of lifecycle functions commonly used in application development:
// app.js |
Note: It is not recommended to do long-time operations in the custom lifecycle function, because the framework has a startup timeout detection.
If your Egg's life-cycle functions are old, we suggest you upgrading to the "class-method" mode. For more you can refer to Upgrade your event functions in your lifecycle.