-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
33 lines (28 loc) · 980 Bytes
/
Copy pathserver.ts
File metadata and controls
33 lines (28 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { createApp } from "./app.ts";
import { closeDB } from "./modules/db.ts";
import { env } from "./modules/env.ts";
import logger from "./modules/logger.ts";
import { closePlugins } from "./modules/pluginLoader.ts";
const app = await createApp();
const port = Number.parseInt(env.PORT, 10);
const server = app.listen(port, () => {
logger.log(`Site listening on port ${port}!`);
});
let shuttingDown = false;
const shutdown = async (signal: string) => {
if (shuttingDown) return;
shuttingDown = true;
logger.log(`${signal} received — shutting down gracefully`);
setTimeout(() => {
logger.error("Shutdown timed out — forcing exit");
process.exit(1);
}, 10_000).unref();
server.closeAllConnections();
server.close(async () => {
await closePlugins();
await closeDB();
process.exit(0);
});
};
process.once("SIGTERM", () => shutdown("SIGTERM"));
process.once("SIGINT", () => shutdown("SIGINT"));