-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
68 lines (55 loc) · 2.29 KB
/
server.js
File metadata and controls
68 lines (55 loc) · 2.29 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
require("module-alias/register");
const dotenv = require("dotenv");
const dotenvExpand = require("dotenv-expand");
// Load and expand environment variables
const myEnv = dotenv.config();
dotenvExpand.expand(myEnv);
// BOOT VALIDATION - Must run BEFORE anything else
require("@bootstrap/env.defaults").applyEnvDefaults();
require("@bootstrap/env.validator").validateEnvironment();
const mongoose = require("mongoose");
const { app } = require("@app");
const { DB_URL } = require("@configs/db.config");
const { PORT_NUMBER } = require("@configs/server.config");
const { logWithTime } = require("@utils/time-stamps.util");
const { errorMessage } = require("@/responses/common/error-handler.response");
const { bootstrapSuperAdmin } = require("@services/bootstrap/super-admin-bootstrap.service");
const { logSystemConfiguration } = require("@services/bootstrap/system-info.service");
(async () => {
try {
// 📋 LOG SYSTEM CONFIGURATION
// await logSystemConfiguration();
// 🔑 DATABASE CONNECTION (CORRECT WAY)
await mongoose.connect(DB_URL);
logWithTime("✅ Connection established with MongoDB Successfully");
// 🛡️ Bootstrap Super Admin
const bootstrapSuccess = await bootstrapSuperAdmin();
if (!bootstrapSuccess) {
logWithTime("❌ Super Admin Bootstrap Failed");
process.exit(1);
}
logWithTime("✅ Super Admin Bootstrap Completed");
// 🔄 Microservice Init
try {
const {
initializeMicroservice,
setupTokenRotationScheduler
} = require("@services/bootstrap/microservice-init.service");
await initializeMicroservice();
setupTokenRotationScheduler();
} catch (err) {
logWithTime("⚠️ Microservice init failed");
errorMessage(err);
}
// 🚀 Start Server
app.listen(PORT_NUMBER, () => {
logWithTime(`🚀 Server running on port ${PORT_NUMBER}`);
require("@cron-jobs");
logWithTime("✅ Cron Jobs Initialized");
});
} catch (err) {
logWithTime("❌ MongoDB Connection Failed");
errorMessage(err);
process.exit(1);
}
})();