-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (35 loc) · 1.31 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
const connectDb = require("./src/database/connect");
const express = require("express");
const dotenv = require("dotenv");
const authentication = require("./src/middleware/authenticator");
const errorHandlerMiddleware = require("./src/middleware/error-handler");
const agenda = require("./src/jobs/agenda");
const notificationService = require("./src/services/notification-service"); // instantiate notification service
// routes
const usersRoute = require("./src/routes/users-route");
const checksRoute = require("./src/routes/checks-route");
const reportsRoute = require("./src/routes/reports-route");
// initialize express
const app = express();
dotenv.config({ path: "./src/configs/config.env" });
// to get request of json data
app.use(express.json({limit: '10kb'})); // limit body size to 10kb
app.use("/api/v1/users", usersRoute);
app.use(authentication);
app.use("/api/v1/checks", checksRoute);
app.use("/api/v1/reports", reportsRoute);
app.use(errorHandlerMiddleware);
// for graceful shutdown
async function graceful() {
await agenda.stop();
process.exit(0);
}
process.on("SIGTERM", graceful);
process.on("SIGINT", graceful);
async function start() {
await connectDb(process.env.MONGODB_URI);
app.listen(process.env.PORT, () => {
console.log(`Server is listening on port ${process.env.PORT}`);
});
}
start();