-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·41 lines (35 loc) · 1.08 KB
/
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
const config = require('./utils/config')
const express = require('express')
const app = express()
const cors = require('cors')
const mongoose = require('mongoose')
const bookingRouter = require('./controllers/booking')
const userRouter = require('./controllers/user')
const middleware = require('./utils/middleware')
const logger = require('./utils/logger')
const adminRouter = require('./controllers/admin')
app.use(cors())
app.use(express.json())
app.use(express.static('build'))
app.use(middleware.requestLogger)
app.use(middleware.tokenExtractor)
app.use(middleware.userExtractor)
mongoose.connect(config.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
})
.then(() => {
logger.info('connected to MongoDB')
})
.catch(err => {
logger.info('fail to connect MongoDB', err.message)
})
app.use('/api/bookings', bookingRouter)
app.use('/api/users', userRouter)
app.use('/api/admin',adminRouter)
app.use(middleware.userAuth)
app.use(middleware.unknownEndpoint)
app.use(middleware.errorHandler)
module.exports = app