-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
73 lines (63 loc) · 2.11 KB
/
Copy pathserver.js
File metadata and controls
73 lines (63 loc) · 2.11 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const app = require("./src/app");
const config = require("./src/config/env");
/**
* Start the HTTP server with configuration validation.
*/
function startServer() {
try {
// Validate environment configuration
config.validateConfig();
const server = app.listen(config.PORT, () => {
printStartupInfo();
});
// Graceful shutdown handling
process.on("SIGTERM", () => {
console.log("\nSIGTERM received. Shutting down gracefully...");
server.close(() => {
console.log("Process terminated.");
process.exit(0);
});
});
process.on("unhandledRejection", (reason, promise) => {
console.error("Unhandled Rejection at:", promise, "reason:", reason);
});
} catch (error) {
console.error("Failed to start server:", error.message);
process.exit(1);
}
}
/**
* Print startup information to console.
*/
function printStartupInfo() {
console.log("\n" + "=".repeat(50));
console.log(" Server started successfully");
console.log("=".repeat(50));
console.log(` URL : http://localhost:${config.PORT}`);
console.log(` Brand : ${config.BRAND_NAME}`);
console.log(` Mode : ${config.DEV_MODE ? "DEVELOPMENT" : "PRODUCTION"}`);
if (config.DEV_MODE) {
console.log(" Note : OTPs logged to console (no real SMS)");
} else {
console.log(` Provider: ${config.SMS_SERVICE_PROVIDER}`);
// Mask sensitive credentials for display
if (config.SMS_SERVICE_PROVIDER === "ALPHASMS") {
const keyMasked = config.ALPHASMS.API_KEY
? `${config.ALPHASMS.API_KEY.slice(0, 3)}...`
: "NOT SET";
console.log(` API Key : ${keyMasked}`);
} else if (config.SMS_SERVICE_PROVIDER === "SENTMYSMS") {
const userMasked = config.SENTMYSMS.USER
? `${config.SENTMYSMS.USER.slice(0, 3)}...`
: "NOT SET";
const keyMasked = config.SENTMYSMS.API_KEY
? `${config.SENTMYSMS.API_KEY.slice(0, 3)}...`
: "NOT SET";
console.log(` User : ${userMasked}`);
console.log(` API Key : ${keyMasked}`);
}
}
console.log("=".repeat(50) + "\n");
}
// Start the server
startServer();