-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
27 lines (24 loc) · 828 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
// imports
const config = require('./utils/config')
const express = require('express')
const app = express()
const logger = require('./utils/logger')
const blogsRouter = require('./controllers/blogs')
const usersRouter = require('./controllers/users')
const loginRouter = require('./controllers/login')
const mongoose = require('mongoose')
const middlewares = require('./utils/middlewares')
// connect to DB
mongoose.set('strictQuery', false)
logger.info('connecting to ', config.MONGODB_URI)
mongoose.connect(config.MONGODB_URI).then(() => {
logger.info('connected to MongoDB')
})
// use middlewares
app.use(express.json())
app.use('/api/users', usersRouter)
app.use('/api/login', loginRouter)
app.use(middlewares.tokenExtractor)
app.use(middlewares.tokenValidator)
app.use('/api/blogs', blogsRouter)
module.exports = app