init
This commit is contained in:
69
server/src/server.ts
Normal file
69
server/src/server.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { createApp } from "./app.js";
|
||||
import { env } from "./config/env.js";
|
||||
import { pruneOldAuthSessions } from "./lib/auth-sessions.js";
|
||||
import { bootstrapAppData } from "./lib/bootstrap.js";
|
||||
import { prisma } from "./lib/prisma.js";
|
||||
import { setLatestStartupReport } from "./lib/startup-state.js";
|
||||
import { assertStartupReadiness } from "./lib/startup-validation.js";
|
||||
import { recordSupportLog } from "./lib/support-log.js";
|
||||
|
||||
async function start() {
|
||||
await bootstrapAppData();
|
||||
const prunedSessionCount = await pruneOldAuthSessions();
|
||||
const startupReport = await assertStartupReadiness();
|
||||
setLatestStartupReport(startupReport);
|
||||
|
||||
recordSupportLog({
|
||||
level: startupReport.status === "PASS" ? "INFO" : startupReport.status === "WARN" ? "WARN" : "ERROR",
|
||||
source: "startup-validation",
|
||||
message: `Startup validation completed with status ${startupReport.status}.`,
|
||||
context: {
|
||||
generatedAt: startupReport.generatedAt,
|
||||
durationMs: startupReport.durationMs,
|
||||
passCount: startupReport.passCount,
|
||||
warnCount: startupReport.warnCount,
|
||||
failCount: startupReport.failCount,
|
||||
prunedSessionCount,
|
||||
},
|
||||
});
|
||||
|
||||
for (const check of startupReport.checks.filter((entry) => entry.status !== "PASS")) {
|
||||
console.warn(`[startup:${check.status.toLowerCase()}] ${check.label}: ${check.message}`);
|
||||
recordSupportLog({
|
||||
level: check.status === "WARN" ? "WARN" : "ERROR",
|
||||
source: "startup-check",
|
||||
message: `${check.label}: ${check.message}`,
|
||||
context: {
|
||||
checkId: check.id,
|
||||
status: check.status,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const app = createApp();
|
||||
const server = app.listen(env.PORT, () => {
|
||||
console.log(`MRP server listening on port ${env.PORT}`);
|
||||
});
|
||||
|
||||
const shutdown = async () => {
|
||||
server.close();
|
||||
await prisma.$disconnect();
|
||||
};
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
}
|
||||
|
||||
start().catch(async (error) => {
|
||||
console.error(error);
|
||||
recordSupportLog({
|
||||
level: "ERROR",
|
||||
source: "server-startup",
|
||||
message: error instanceof Error ? error.message : "Server startup failed.",
|
||||
context: {
|
||||
stack: error instanceof Error ? error.stack ?? null : null,
|
||||
},
|
||||
});
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user