import { buildApp } from "./app"; import { config } from "./config"; import { closeDb, getDb } from "@spinza/database"; import { syncGames } from "@spinza/database/sync-games"; import { closeRedis } from "./lib/redis"; async function main() { const app = await buildApp(); // Keep the games table in sync with the shipped library on boot (lifecycle respects certifications). try { const reports = await syncGames(getDb()); app.log.info({ published: reports.filter((r) => r.lifecycle === "published").length, total: reports.length }, "game library synced"); } catch (e) { app.log.error({ err: e }, "game sync failed"); } await app.listen({ port: config.port, host: config.host }); app.log.info(`Spinza API listening on http://${config.host}:${config.port} (${config.env})`); const shutdown = async (signal: string) => { app.log.info({ signal }, "shutting down"); await app.close(); await closeDb(); await closeRedis(); process.exit(0); }; process.on("SIGINT", () => void shutdown("SIGINT")); process.on("SIGTERM", () => void shutdown("SIGTERM")); } main().catch((e) => { console.error(e); process.exit(1); });