-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (22 loc) · 793 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
const express = require('express');
const AppError = require('./utils/appError');
const globalErrorHandler = require('./controllers/errorController');
const userRouter = require('./routes/userRoutes');
const app = express();
/* A middleware that parses the body of the request and makes it available on the request object. */
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
//
app.use((req,res,next) => {
// console.log(req.headers)
next();
})
// ROUTES
app.use("/api/v1/users", userRouter);
/* A ROUTE HANDLER */
app.all('*', (req,res,next) => {
next(new AppError(`can't find ${req.originalUrl} on this server`,404));
// when there is a arg in next go direct to err middleware and pass others
});
app.use(globalErrorHandler);
module.exports = app;