init
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { config } from './config.js';
|
||||
import { closePool } from './db/pool.js';
|
||||
import { runMigrations } from './db/migrate.js';
|
||||
import { buildServer } from './server.js';
|
||||
|
||||
async function main(): Promise<void> {
|
||||
await runMigrations();
|
||||
|
||||
const app = await buildServer();
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user