-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (39 loc) · 1.07 KB
/
server.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* @file server.js
* @description Server configuration and initialization.
*/
// Load environment variables from .env file
require("dotenv").config();
// Load required modules
const express = require("express");
const routes = require("./src/routes");
const port = process.env.PORT || 3000;
const host = process.env.HOST || "localhost";
const app = express();
// Middleware setup
app.use(express.static("public"));
// Load the renderer (EJS)
app.set("views", "./src/views");
app.set("view engine", "ejs");
// Routes setup
app.use("/", routes);
// Start the server
const server = app.listen(port, host, () => {
console.log(`Server running at http://${host}:${port}/`);
});
// Handle SIGTERM gracefully
process.on("SIGTERM", async () => {
console.info("SIGTERM signal received.");
console.log("Closing server...");
await app.close();
});
// Handle SIGINT gracefully
process.on("SIGINT", async () => {
console.info("SIGINT signal received.");
console.log("Closing server...");
await app.close();
});
app.close = () => {
server.close();
};
module.exports = app;