-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
34 lines (29 loc) · 961 Bytes
/
index.ts
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
34
import dotenv from "dotenv";
// Important: Don't place any imports above dotenv.config() as they use environment variables that needs to be loaded first
dotenv.config();
import { startServer, closeServer } from "./server";
async function gracefulShutdown(signal: string): Promise<void> {
console.log(signal);
console.log("Gracefully stopping... (press Ctrl+C again to force)");
try {
await closeServer();
process.exit(0);
} catch (err) {
console.error(err);
process.exit(1);
}
}
function catchTermination(): void {
process.once("SIGUSR2", () => process.kill(process.pid, "SIGUSR2")); // For nodemon graceless restarts
const signals = ["SIGHUP", "SIGINT", "SIGTERM", "SIGQUIT"];
signals.forEach((signal: any) => process.once(signal, gracefulShutdown));
}
(async function main(): Promise<void> {
try {
await startServer();
catchTermination();
} catch (err) {
console.error(err);
process.exit(1);
}
})();