import { buildApp } from "./app/buildApp.js";
import { env } from "./config/env.js";
import { pool } from "./core/db/db.js";
import { syncPermissions } from "./modules/access/index.js";

// New permissions and their names reach the database on every start; grants already set are kept.
await syncPermissions(pool);
const app = await buildApp();
for (const signal of ["SIGINT", "SIGTERM"] as const) process.once(signal, () => void app.close().then(() => pool.end()).then(() => process.exit(0)));
await app.listen({ port: env.PORT, host: env.HOST });
