HTTP-Endpunkte und Anwendungsaufbau
Eingaben werden mit zod validiert, jede aendernde Aktion schreibt ins Audit-Log. Beim ersten Start entsteht ein Administrator samt Startwerten fuer die Produkterkennung; solange ein Erstpasswort gilt, bleiben schreibende Wege bis auf den Passwortwechsel gesperrt. Nicht-API-Pfade fallen auf die SPA zurueck, damit Deep-Links funktionieren.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { buildApp } from './app.js';
|
||||
import { bootstrap } from './bootstrap.js';
|
||||
import { cleanupExpiredSessions } from './auth/session.js';
|
||||
import { prisma } from './db.js';
|
||||
import { env } from './env.js';
|
||||
|
||||
const SESSION_CLEANUP_INTERVAL_MS = 60 * 60 * 1000;
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const app = await buildApp();
|
||||
|
||||
try {
|
||||
await prisma.$queryRaw`SELECT 1`;
|
||||
} catch (error) {
|
||||
app.log.error({ err: error }, 'Keine Verbindung zur Datenbank');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await bootstrap({
|
||||
info: (msg) => app.log.info(msg),
|
||||
warn: (msg) => app.log.warn(msg),
|
||||
});
|
||||
|
||||
const cleanup = setInterval(() => {
|
||||
cleanupExpiredSessions()
|
||||
.then((count) => {
|
||||
if (count > 0) app.log.debug(`${count} abgelaufene Sitzungen entfernt`);
|
||||
})
|
||||
.catch((error) => app.log.warn({ err: error }, 'Aufraeumen der Sitzungen fehlgeschlagen'));
|
||||
}, SESSION_CLEANUP_INTERVAL_MS);
|
||||
cleanup.unref();
|
||||
|
||||
const shutdown = async (signal: string): Promise<void> => {
|
||||
app.log.info(`${signal} empfangen, fahre herunter`);
|
||||
clearInterval(cleanup);
|
||||
await app.close();
|
||||
await prisma.$disconnect();
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
process.on('SIGTERM', () => void shutdown('SIGTERM'));
|
||||
process.on('SIGINT', () => void shutdown('SIGINT'));
|
||||
|
||||
await app.listen({ port: env.PORT, host: env.HOST });
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error('Start fehlgeschlagen:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user