25 lines
929 B
TypeScript
25 lines
929 B
TypeScript
import { buildApp, type AppWithAuthSessionStore } from "./app.js";
|
|
import { loadConfig } from "./config.js";
|
|
import { formatStartupFailure } from "./startup-error.js";
|
|
|
|
async function start(): Promise<void> {
|
|
const config = loadConfig(process.env);
|
|
const app = buildApp(config) as AppWithAuthSessionStore;
|
|
const sessions = app.thothiiAuthSessionStore;
|
|
if (sessions) {
|
|
await sessions.prune();
|
|
const interval = setInterval(() => {
|
|
void sessions.prune().catch(() => app.log.warn({ component: "auth-session-prune" }, "auth session pruning failed"));
|
|
}, 15 * 60 * 1000);
|
|
interval.unref();
|
|
app.addHook("onClose", async () => clearInterval(interval));
|
|
}
|
|
const address = await app.listen({ port: config.port, host: config.host });
|
|
console.log(`backend listening on ${address}`);
|
|
}
|
|
|
|
void start().catch((error: unknown) => {
|
|
console.error(formatStartupFailure(error));
|
|
process.exitCode = 1;
|
|
});
|