37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { config } from './config.js';
|
|
import { closePool } from './db/pool.js';
|
|
import { runMigrations } from './db/migrate.js';
|
|
import { iconCount, loadIcons } from './lib/iconRegistry.js';
|
|
import { buildServer } from './server.js';
|
|
|
|
async function main(): Promise<void> {
|
|
await runMigrations();
|
|
await loadIcons();
|
|
|
|
const app = await buildServer();
|
|
app.log.info(`Icon registry ready: ${iconCount()} item textures available`);
|
|
await app.listen({ host: config.host, port: config.port });
|
|
|
|
const scheme = config.tls.enabled ? 'https' : 'http';
|
|
app.log.info(`API docs: ${scheme}://localhost:${config.port}/api/docs`);
|
|
app.log.info(`Live feed: ${scheme === 'https' ? 'wss' : 'ws'}://localhost:${config.port}/api/ws/live`);
|
|
|
|
let closing = false;
|
|
const shutdown = async (signal: string): Promise<void> => {
|
|
if (closing) return;
|
|
closing = true;
|
|
app.log.info(`Received ${signal}, shutting down`);
|
|
await app.close();
|
|
await closePool();
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on('SIGINT', () => void shutdown('SIGINT'));
|
|
process.on('SIGTERM', () => void shutdown('SIGTERM'));
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error('Fatal startup error:', err);
|
|
process.exit(1);
|
|
});
|