* refactor: add nitro bootstrap plugin to ensure app is started before first call * refactor(bootstrap): avoid duplicate event firing
26 lines
574 B
TypeScript
26 lines
574 B
TypeScript
import * as schema from "../../db/schema";
|
|
import { runDbMigrations, setSchema } from "../../db/db";
|
|
import { runMigrations } from "./migrations";
|
|
import { startup } from "./startup";
|
|
|
|
let bootstrapPromise: Promise<void> | undefined;
|
|
|
|
const runBootstrap = async () => {
|
|
setSchema(schema);
|
|
runDbMigrations();
|
|
await runMigrations();
|
|
await startup();
|
|
};
|
|
|
|
export const bootstrapApplication = async () => {
|
|
if (!bootstrapPromise) {
|
|
bootstrapPromise = runBootstrap();
|
|
}
|
|
|
|
try {
|
|
await bootstrapPromise;
|
|
} catch (err) {
|
|
bootstrapPromise = undefined;
|
|
throw err;
|
|
}
|
|
};
|