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