33 lines
727 B
TypeScript
33 lines
727 B
TypeScript
import { buildApp } from './app.js';
|
|
import { env } from './config/env.js';
|
|
|
|
async function main(): Promise<void> {
|
|
const app = await buildApp();
|
|
try {
|
|
await app.listen({ port: env.BACKEND_PORT, host: '0.0.0.0' });
|
|
} catch (err) {
|
|
app.log.error({ err }, 'failed to start');
|
|
process.exit(1);
|
|
}
|
|
|
|
const shutdown = async (signal: NodeJS.Signals) => {
|
|
app.log.info({ signal }, 'shutting down');
|
|
try {
|
|
await app.close();
|
|
process.exit(0);
|
|
} catch (err) {
|
|
app.log.error({ err }, 'shutdown error');
|
|
process.exit(1);
|
|
}
|
|
};
|
|
|
|
process.on('SIGTERM', () => {
|
|
void shutdown('SIGTERM');
|
|
});
|
|
process.on('SIGINT', () => {
|
|
void shutdown('SIGINT');
|
|
});
|
|
}
|
|
|
|
void main();
|