chore: ensures onInit is called after initHTTP

This commit is contained in:
James
2023-01-19 16:06:50 -05:00
parent 6023559142
commit 6dc688cefd
4 changed files with 11 additions and 5 deletions

View File

@@ -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;
}
}

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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');
},
});