-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (32 loc) · 962 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
39
40
41
42
43
44
const express = require('express');
const morgan = require('morgan');
const tourRouter = require('./routes/tourRoutes');
const userRouter = require('./routes/userRoutes');
const app = express();
//1) Middleware
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
}
app.use(morgan('dev'));
app.use(express.json());
//searching static files
app.use(express.static(`${__dirname}/public/`));
app.use((req, res, next) => {
console.log('Hello from the middleware!!');
next();
});
app.use((req, res, next) => {
req.requestTime = new Date().toISOString();
next();
});
// 2) Route handlers
// app.get('/api/v1/tours', getAllTours);
// app.get('/api/v1/tours/:id', getTour);
// app.post('/api/v1/tours', createTour);
// app.patch('/api/v1/tours/:id', updateTour);
// app.delete('/api/v1/tours/:id', deleteTour);
//3)Routes
app.use('/api/v1/tours', tourRouter);
app.use('/api/v1/users', userRouter);
//4)Server
module.exports = app;