-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (28 loc) · 922 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
33
34
35
36
37
38
const express = require('express');
const morgan = require('morgan');
const AppErro = require('./utils/app_erro');
const bp = require('body-parser');
const tourRouter = require('./routes/tourRoute');
const userRouter = require('./routes/userRoute');
const globalErro = require('./controllers/error_controller');
const app = express();
// 1) MIDDLEWARE
//This is how we use middle ware
// if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
// }
// app.use(express.json());
// app.use(express.static(`${__dirname}/public`));
app.use(bp.json());
app.use(bp.urlencoded({ extended: true }));
app.use((req, res, next) => {
req.requestTime = new Date().toISOString();
next();
});
app.use('/api/v1/tours', tourRouter);
app.use('/api/v1/users', userRouter);
app.all('*', (req, res, next) => {
next(new AppErro(`cant find ${req.originalUrl}`, 404));
});
app.use(globalErro);
module.exports = app;