-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (36 loc) · 1.25 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
42
const config = require('./utils/config')
const express = require('express')
require('express-async-errors')
const app = express()
// const cors = require('cors')
const personsRouter = require('./controllers/persons')
const blogsRouter = require('./controllers/blogs')
const usersRouter = require('./controllers/users')
const loginRouter = require('./controllers/login')
const middleware = require('./utils/middleware')
const logger = require('./utils/logger')
const mongoose = require('mongoose')
logger.info('Connecting to', config.MONGODB_URI)
mongoose.connect(config.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
//for warning `findOneAndUpdate()` and `findOneAndDelete()`
useFindAndModify: false
}).then(() => {
logger.info('Connect to MongoDB sucessed')
}).catch(err => {
logger.error('Connect failed:', err.message)
})
// app.use(cors)
app.use(express.static('build'))
app.use(express.json())
app.use(middleware.requestLogger)
app.use(middleware.tokenFormater)
app.use('/api/persons', personsRouter)
app.use('/api/blogs', blogsRouter)
app.use('/api/users', usersRouter)
app.use('/api/login', loginRouter)
app.use(middleware.unknownEndpoint)
app.use(middleware.errorHandler)
module.exports = app