mirror of
https://github.com/strapi/strapi.git
synced 2025-10-23 14:00:47 +00:00
Merge pull request #20547 from strapi/fix/lifecycle-order
fix: lifecycle order, provider 1st during bootstrap
This commit is contained in:
commit
fa2d17519f
@ -400,7 +400,8 @@ class Strapi extends Container implements Core.Strapi {
|
||||
await provider.register?.(this);
|
||||
}
|
||||
|
||||
await this.runLifecyclesFunctions(utils.LIFECYCLES.REGISTER);
|
||||
await this.runPluginsLifecycles(utils.LIFECYCLES.REGISTER);
|
||||
await this.runUserLifecycles(utils.LIFECYCLES.REGISTER);
|
||||
|
||||
// NOTE: Swap type customField for underlying data type
|
||||
utils.convertCustomFieldType(this);
|
||||
@ -458,12 +459,14 @@ class Strapi extends Container implements Core.Strapi {
|
||||
|
||||
await this.contentAPI.permissions.registerActions();
|
||||
|
||||
await this.runLifecyclesFunctions(utils.LIFECYCLES.BOOTSTRAP);
|
||||
await this.runPluginsLifecycles(utils.LIFECYCLES.BOOTSTRAP);
|
||||
|
||||
for (const provider of providers) {
|
||||
await provider.bootstrap?.(this);
|
||||
}
|
||||
|
||||
await this.runUserLifecycles(utils.LIFECYCLES.BOOTSTRAP);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -491,12 +494,14 @@ class Strapi extends Container implements Core.Strapi {
|
||||
|
||||
async destroy() {
|
||||
this.log.info('Shutting down Strapi');
|
||||
await this.runLifecyclesFunctions(utils.LIFECYCLES.DESTROY);
|
||||
await this.runPluginsLifecycles(utils.LIFECYCLES.DESTROY);
|
||||
|
||||
for (const provider of providers) {
|
||||
await provider.destroy?.(this);
|
||||
}
|
||||
|
||||
await this.runUserLifecycles(utils.LIFECYCLES.DESTROY);
|
||||
|
||||
await this.server.destroy();
|
||||
|
||||
this.eventHub.destroy();
|
||||
@ -511,10 +516,12 @@ class Strapi extends Container implements Core.Strapi {
|
||||
this.log.info('Strapi has been shut down');
|
||||
}
|
||||
|
||||
async runLifecyclesFunctions(lifecycleName: 'register' | 'bootstrap' | 'destroy') {
|
||||
async runPluginsLifecycles(lifecycleName: 'register' | 'bootstrap' | 'destroy') {
|
||||
// plugins
|
||||
await this.get('modules')[lifecycleName]();
|
||||
}
|
||||
|
||||
async runUserLifecycles(lifecycleName: 'register' | 'bootstrap' | 'destroy') {
|
||||
// user
|
||||
const userLifecycleFunction = this.app && this.app[lifecycleName];
|
||||
if (isFunction(userLifecycleFunction)) {
|
||||
|
@ -84,7 +84,8 @@ export interface Strapi extends Container {
|
||||
stop(exitCode?: number): never;
|
||||
register(): Promise<Strapi>;
|
||||
bootstrap(): Promise<Strapi>;
|
||||
runLifecyclesFunctions(lifecycleName: 'register' | 'bootstrap' | 'destroy'): Promise<void>;
|
||||
runPluginsLifecycles(lifecycleName: 'register' | 'bootstrap' | 'destroy'): Promise<void>;
|
||||
runUserLifecycles(lifecycleName: 'register' | 'bootstrap' | 'destroy'): Promise<void>;
|
||||
getModel<TSchemaUID extends UID.Schema>(
|
||||
uid: TSchemaUID
|
||||
): TSchemaUID extends UID.ContentType
|
||||
|
Loading…
x
Reference in New Issue
Block a user