chore: ensures onInit is called after initHTTP
This commit is contained in:
@@ -13,6 +13,10 @@ export class PayloadHTTP extends BasePayload<GeneratedTypes> {
|
||||
async init(options: InitOptions): Promise<Payload> {
|
||||
const payload = await initHTTP(options);
|
||||
Object.assign(this, payload);
|
||||
|
||||
if (typeof options.onInit === 'function') await options.onInit(this);
|
||||
if (typeof this.config.onInit === 'function') await this.config.onInit(this);
|
||||
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
import express, { NextFunction, Response } from 'express';
|
||||
import { Config as GeneratedTypes } from 'payload/generated-types';
|
||||
import { InitOptions } from './config/types';
|
||||
|
||||
import authenticate from './express/middleware/authenticate';
|
||||
@@ -22,6 +21,7 @@ import mountEndpoints from './express/mountEndpoints';
|
||||
import { Payload, getPayload } from './payload';
|
||||
|
||||
export const initHTTP = async (options: InitOptions): Promise<Payload> => {
|
||||
options.local = false;
|
||||
const payload = await getPayload(options);
|
||||
|
||||
if (!options.local) {
|
||||
|
||||
@@ -199,8 +199,10 @@ export class BasePayload<TGeneratedTypes extends GeneratedTypes> {
|
||||
|
||||
serverInitTelemetry(this);
|
||||
|
||||
if (options.local !== false) {
|
||||
if (typeof options.onInit === 'function') await options.onInit(this);
|
||||
if (typeof this.config.onInit === 'function') await this.config.onInit(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ const startDev = async () => {
|
||||
fromName: 'Payload',
|
||||
fromAddress: 'hello@payloadcms.com',
|
||||
},
|
||||
onInit: async (app) => {
|
||||
app.logger.info('Payload Dev Server Initialized');
|
||||
onInit: async () => {
|
||||
payload.logger.info('Payload Dev Server Initialized');
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user