-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (26 loc) · 798 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 morgan = require('morgan');
const tourRouter = require('./routes/tourRoutes');
const userRouter = require('./routes/userRoutes');
const app = express();
//MIDDLEWARES
//console.log(process.env.NODE_ENV);
if (process.env.NODE_ENV !== 'development') {
app.use(morgan('dev'));
}
app.use(express.json()); //middleware-function that modifies the incoming request data.
//serve static files
app.use(express.static(`${__dirname}/public`));
//global middleware
app.use((req, res, next) => {
console.log('HELLO FROM THE MIDDLEWARE');
next();
});
app.use((req, res, next) => {
req.requestTime = new Date().toDateString();
next();
});
//mounting routes
app.use('/api/v1/tours', tourRouter);
app.use('/api/v1/users', userRouter);
module.exports = app;