-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
39 lines (31 loc) · 1.17 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
require("dotenv").config({ path: "./config/config.env" });
const express = require("express");
const app = express();
const cookieParser = require("cookie-parser");
const connectDatabase = require("./config/dataBase");
const logger = require("morgan");
const cors = require("cors");
app.use(cors());
app.use(logger("dev"));
app.use(express.json());
app.use(cookieParser());
// Db connection
connectDatabase();
// Import all routes
const indexRouter = require("./routes");
const adminRouter = require("./routes/admin");
const developerRouter = require("./routes/developer");
const buyerRouter = require("./routes/buyer");
const ErrorResponse = require("./utils/ErrorResponse");
const errorHandler = require("./middlewares/errorHandler");
const { getUserAccess, getAdminAccess } = require("./middlewares");
app.use("/api/v1", indexRouter);
app.use("/api/v1/admin", getAdminAccess, adminRouter);
app.use("/api/v1/developer", getUserAccess, developerRouter);
app.use("/api/v1/buyer", getUserAccess, buyerRouter);
// Catching 404 requests and passing to errorHandler
app.use((req, res, next) => {
next(new ErrorResponse(404, "Not found"));
});
app.use(errorHandler);
module.exports = app;