-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (28 loc) · 885 Bytes
/
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
const express = require("express");
const app = express();
const morgan = require("morgan");
const userRouter = require("./Routes/userRoute");
const expenseRouter = require("./Routes/expenseRoute");
const appError = require("./utils/appError");
const globalErrorHandler = require("./Controller/errorController");
if (process.env.NODE_ENV == "developement") {
app.use(morgan("dev"));
}
app.use((req, res, next) => {
console.log("Welcome from the global middleware");
next();
});
app.use(express.json());
app.use((req, res, next) => {
const date = new Date().toISOString();
req.date = date;
next();
});
app.use("/api/expenses", expenseRouter);
app.use("/api/user", userRouter);
// To handle all other URL
app.all("*", (req, res, next) => {
next(new appError(`Can't find ${req.originalUrl} on this server.`, 404));
});
app.use(globalErrorHandler);
module.exports = app;