-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
30 lines (24 loc) · 868 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
const config = require('./utils/config')
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const booksRouter = require('./controllers/bookController')
const authorRouter = require('./controllers/authorController')
const middleware = require('./utils/middleware')
const mongoose = require('mongoose')
console.log("connecting to DB")
mongoose.connect(config.DB_URL, { useNewUrlParser: true })
.then(() => {
console.log("connected to Mongo DB")
})
.catch((err) => {
console.log("connection to Mongo DB failed:", err.message)
})
app.use(express.static('build'))
app.use(bodyParser.json())
app.use(middleware.requestLogger)
app.use('/api/books', booksRouter)
app.use('/api/authors', authorRouter)
app.use(middleware.unknownEndpoint)
app.use(middleware.errorHandler)
module.exports = app