-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (31 loc) · 1.19 KB
/
app.js
File metadata and controls
40 lines (31 loc) · 1.19 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
const express = require("express");
const morgan = require("morgan");
// eslint-disable-next-line import/no-extraneous-dependencies
const cors = require("cors");
const AppError = require("./utils/appError");
const globalErrorHandler = require("./controllers/errorController");
const accreditationRouter = require("./routes/accreditationRoutes");
const votingRouter = require("./routes/votingRoutes");
const superAdminRouter = require("./routes/superAdminRoutes");
const app = express();
// 1) GLOBAL MIDDLEWARES
if (process.env.NODE_ENV === "development") {
app.use(morgan("dev"));
}
app.use(express.json());
app.use(express.static(`${__dirname}/public`));
app.use((req, res, next) => {
req.requestTime = new Date().toISOString();
next();
});
app.use("/api/v1/accreditation", cors(), accreditationRouter);
app.use("/api/v1/voting", cors(), votingRouter);
app.use("/api/v1/superadmin", cors(), superAdminRouter);
app.all("*", (req, res, next) => {
// const err = new Error(`Can't find ${req.originalUrl} on this server!`);
// err.status = "fail";
// err.statusCode = 404;
next(new AppError(`Can't find ${req.originalUrl} on this server!`, 404));
});
app.use(globalErrorHandler);
module.exports = app;