diff --git a/packages/chronicle/src/cli/commands/dev.ts b/packages/chronicle/src/cli/commands/dev.ts index 80a19f96..ee67b290 100644 --- a/packages/chronicle/src/cli/commands/dev.ts +++ b/packages/chronicle/src/cli/commands/dev.ts @@ -28,4 +28,16 @@ export const devCommand = new Command('dev') await server.listen(); server.printUrls(); + + let shuttingDown = false; + const shutdown = async () => { + if (shuttingDown) return; + shuttingDown = true; + try { + await server.close(); + } catch { /* ignore close errors */ } + process.exit(0); + }; + process.once('SIGINT', shutdown); + process.once('SIGTERM', shutdown); }); diff --git a/packages/chronicle/src/cli/commands/start.ts b/packages/chronicle/src/cli/commands/start.ts index 7be31f26..4bb86b3f 100644 --- a/packages/chronicle/src/cli/commands/start.ts +++ b/packages/chronicle/src/cli/commands/start.ts @@ -26,4 +26,16 @@ export const startCommand = new Command('start') }); server.printUrls(); + + let shuttingDown = false; + const shutdown = async () => { + if (shuttingDown) return; + shuttingDown = true; + try { + await server.close(); + } catch { /* ignore close errors */ } + process.exit(0); + }; + process.once('SIGINT', shutdown); + process.once('SIGTERM', shutdown); });