refactor: extract common setup in initModule function
Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
This commit is contained in:
parent
ca2a2cb74f
commit
48b3c9a87f
4 changed files with 21 additions and 23 deletions
|
|
@ -3,22 +3,15 @@ import { shutdown } from "./server/modules/lifecycle/shutdown";
|
|||
import { runCLI } from "./server/cli";
|
||||
import { createStartHandler, defaultStreamHandler, defineHandlerCallback } from "@tanstack/react-start/server";
|
||||
import { createServerEntry } from "@tanstack/react-start/server-entry";
|
||||
import { initAuth } from "~/server/lib/auth";
|
||||
import { setSchema } from "./server/db/db";
|
||||
import * as schema from "./server/db/schema";
|
||||
import { toMessage } from "./server/utils/errors";
|
||||
import { initModules } from "./server/modules/lifecycle/bootstrap";
|
||||
|
||||
await initModules();
|
||||
|
||||
const cliRun = await runCLI(Bun.argv);
|
||||
if (cliRun) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
setSchema(schema);
|
||||
await initAuth().catch((err) => {
|
||||
logger.error(`Error initializing auth: ${toMessage(err)}`);
|
||||
throw err;
|
||||
});
|
||||
|
||||
const customHandler = defineHandlerCallback((ctx) => {
|
||||
return defaultStreamHandler(ctx);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,24 @@ import * as schema from "../../db/schema";
|
|||
import { runDbMigrations, setSchema } from "../../db/db";
|
||||
import { runMigrations } from "./migrations";
|
||||
import { startup } from "./startup";
|
||||
import { initAuth } from "../../lib/auth";
|
||||
import { logger } from "../../utils/logger";
|
||||
import { toMessage } from "../../utils/errors";
|
||||
|
||||
let bootstrapPromise: Promise<void> | undefined;
|
||||
|
||||
const runBootstrap = async () => {
|
||||
export const initModules = async () => {
|
||||
setSchema(schema);
|
||||
|
||||
await initAuth().catch((err) => {
|
||||
logger.error(`Error initializing auth: ${toMessage(err)}`);
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
const runBootstrap = async () => {
|
||||
await initModules();
|
||||
|
||||
runDbMigrations();
|
||||
await runMigrations();
|
||||
await startup();
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ import { repositoriesService } from "../repositories/repositories.service";
|
|||
import { notificationsService } from "../notifications/notifications.service";
|
||||
import { VolumeAutoRemountJob } from "~/server/jobs/auto-remount";
|
||||
import { cache } from "~/server/utils/cache";
|
||||
import { initAuth } from "~/server/lib/auth";
|
||||
import { toMessage } from "~/server/utils/errors";
|
||||
import { withContext } from "~/server/core/request-context";
|
||||
|
||||
const ensureLatestConfigurationSchema = async () => {
|
||||
|
|
@ -54,11 +52,6 @@ export const startup = async () => {
|
|||
await Scheduler.start();
|
||||
await Scheduler.clear();
|
||||
|
||||
await initAuth().catch((err) => {
|
||||
logger.error(`Error initializing auth: ${toMessage(err)}`);
|
||||
throw err;
|
||||
});
|
||||
|
||||
await ensureLatestConfigurationSchema();
|
||||
|
||||
const volumes = await db.query.volumesTable.findMany({
|
||||
|
|
|
|||
|
|
@ -2,11 +2,9 @@ import { beforeAll, mock } from "bun:test";
|
|||
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
||||
import path from "node:path";
|
||||
import { cwd } from "node:process";
|
||||
import * as schema from "~/server/db/schema";
|
||||
import { db, setSchema } from "~/server/db/db";
|
||||
import { initAuth } from "~/server/lib/auth";
|
||||
import { db } from "~/server/db/db";
|
||||
import { initModules } from "../server/modules/lifecycle/bootstrap";
|
||||
|
||||
setSchema(schema);
|
||||
|
||||
void mock.module("~/server/utils/logger", () => ({
|
||||
logger: {
|
||||
|
|
@ -27,7 +25,8 @@ void mock.module("~/server/utils/crypto", () => ({
|
|||
}));
|
||||
|
||||
beforeAll(async () => {
|
||||
await initModules();
|
||||
|
||||
const migrationsFolder = path.join(cwd(), "app", "drizzle");
|
||||
migrate(db, { migrationsFolder });
|
||||
await initAuth();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue