-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (48 loc) · 1.46 KB
/
app.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
const config = require("./src/config");
if (config.APM_ENABLED) {
console.log('APM is enabled');
const { apm } = require('./src/adapters');
if (apm.isStarted()) {
console.log('APM is started');
} else {
console.log('APM has not started');
}
}else{
console.log('APM is not enabled');
}
const express = require("express");
const { logger } = require("./src/helpers")
const bodyParser = require("body-parser");
const cors = require("cors");
// Import routes, controllers etc.
const routes = require("./src/routes");
require("./src/adapters").db; // Adjust the path as needed
const errorHandlerUtil = require("./src/utils/errorHandler.util");
// Load configuration settings
const port = config.PORT
// Create an Express application
const app = express();
// Middleware
app.use(bodyParser.json());
app.use(cors());
// eslint-disable-next-line no-undef
if (config.APM_ENABLED) app.use(apm?.middleware.connect());
// Define your routes and controllers
app.use("/api/test", routes.testRoute);
app.use("/api/user", routes.userRoute);
// Start the server
async function startServer() {
try {
// await connect(); // Establish the database connection
app.listen(port, () => {
logger.info(`Server is running on port ${port}`);
});
} catch (error) {
logger.error("Error starting the server:", error);
// eslint-disable-next-line no-undef
process.exit(1);
}
}
// Error middleware & exception handler
errorHandlerUtil(app);
startServer();