-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
32 lines (26 loc) · 891 Bytes
/
main.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
import fastify from "fastify";
import { homeController } from "./src/home.controller";
import { charactersController } from "./src/characters/characters.controller";
async function bootstrap() {
// Create Fastify app instance
const app = fastify({ logger: true });
// Docker health check
app.get("/health", (_req, res) => {
res.send("[+] Health check successful...");
});
app.register(homeController);
app.register(charactersController, { prefix: "api/v1/characters" });
// Start the server
const port = process.env.PORT ?? 3000;
await app.listen({ port: +port });
// Boilerplate for handling signals to gracefully shutdown a server
["SIGINT", "SIGTERM"].forEach((signal) => {
process.on(signal, async () => {
await app.close();
console.log("\n[+] Server Is Closed.");
process.exit(0);
});
});
}
// Start the server
bootstrap();