-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (58 loc) · 1.55 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const audit = require("express-requests-logger");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const express = require("express");
const path = require("path");
const { MONGODB_CONN, PORT, LOGIN_PATH, URL } = require("./config");
const { cors } = require("./middlewares/cors");
const { connectToDatabase } = require("./database/connect");
const { logger } = require("./logger");
const { apiRouter, pagesRouter } = require("./routes");
const app = express();
connectToDatabase(MONGODB_CONN);
app.use(
audit({
logger: logger,
excludeURLs: ["ping"],
levels: {
"1xx": "info",
"2xx": "info",
"3xx": "info",
401: "warn",
403: "warn",
"4xx": "info",
503: "warn",
"5xx": "error",
},
})
);
app.use(
cors,
cookieParser(),
bodyParser.json(),
apiRouter,
pagesRouter,
express.static(path.join(path.resolve(), "./public"))
);
app.get("/", (req, res) => {
res.redirect(LOGIN_PATH);
});
app.listen(PORT, async () => {
let chalk;
try {
// Use dynamic import to import chalk as an ES Module
const chalkModule = await import("chalk");
chalk = chalkModule.default;
// eslint-disable-next-line no-unused-vars
} catch (err) {
// If dynamic import fails, fallback to requiring chalk as a CommonJS module
chalk = require("chalk");
}
logger.info(
chalk.whiteBright("❥ App is running on "),
chalk.underline.cyan(PORT),
chalk.whiteBright("port."),
chalk.yellow("\n❥ Join now ☞"),
chalk.underline.green(`${URL}\n`)
);
});