-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (45 loc) · 1.41 KB
/
server.js
File metadata and controls
54 lines (45 loc) · 1.41 KB
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
52
53
54
//* LIB
const https = require("https");
const fs = require("fs");
const path = require("path");
//* IMPORT
const app = require("./src/app");
const {
app: { port: PORT },
} = require("./src/commons/configs/app.config");
const logger = require("./src/loggers/winston.log");
const initRedis = require("./src/databases/init.redis");
// HTTP
const server = app.listen(PORT, () => {
console.info(`💸 Api backend start with http://localhost:${PORT} 🔥`);
});
// HTTPS
// const sslServer = https.createServer(
// {
// // Todo: C1
// // key: fs.readFileSync(path.join(__dirname, "cert", "key.pem")),
// // cert: fs.readFileSync(path.join(__dirname, "cert", "cert.pem")),
// // Todo: C2
// key: fs.readFileSync(path.join(__dirname, "cert", "key.pem")),
// cert: fs.readFileSync(path.join(__dirname, "cert", "cert.pem")),
// },
// app
// );
// sslServer.listen(PORT, () => {
// console.info(`💸 Api backend start with https://localhost:${PORT} 🔥`);
// });
const cleanup = () => {
initRedis.closeRedis();
};
process.on("exit", cleanup);
process.on("unhandledRejection", (reason, promise) => {
logger.error(`Unhandled Rejection at: ${promise}, reason: ${reason}`);
});
process.on("uncaughtException", (error) => {
logger.error(`Uncaught Exception thrown: ${error.message}`);
cleanup();
});
process.on("SIGINT", () => {
server.close(() => console.log(`Exit Server Express`));
cleanup();
});