cleanshsutdown
This commit is contained in:
+18
-2
@@ -3,6 +3,7 @@ import nunjucks from 'nunjucks';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { formatCents } from './money.js';
|
||||
import { db } from './db.js';
|
||||
import ordersRouter from './routes/orders.js';
|
||||
import customersRouter from './routes/customers.js';
|
||||
import clocksRouter from './routes/clocks.js';
|
||||
@@ -40,7 +41,22 @@ app.use((err: unknown, _req: express.Request, res: express.Response, _next: expr
|
||||
});
|
||||
|
||||
const PORT = process.env.PORT ? Number(process.env.PORT) : 3000;
|
||||
const HOST = '127.0.0.1';
|
||||
app.listen(PORT, HOST, () => {
|
||||
const HOST = process.env.HOST || '127.0.0.1';
|
||||
const server = app.listen(PORT, HOST, () => {
|
||||
console.log(`Harding's Clocks running at http://${HOST}:${PORT}`);
|
||||
});
|
||||
|
||||
function shutdown(signal: string) {
|
||||
console.log(`${signal} received, shutting down`);
|
||||
server.close((err) => {
|
||||
db.close();
|
||||
if (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
|
||||
Reference in New Issue
Block a user