-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 996 Bytes
/
index.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
const express = require('express')
const app = express()
const cors = require('cors')
const mongoose = require('mongoose')
const requireDir = require('require-dir')
requireDir('./src/models')
require('dotenv').config()
const mainRoute = require('./src/routes/mainRoute')
const swaggerUI = require('swagger-ui-express')
const swaggerJsDoc = require('swagger-jsdoc')
const swaggerOptions = require('./src/config/swagger-options')
app.use(express.json())
app.use(cors())
app.use(express.urlencoded({ extended: false }))
const specs = swaggerJsDoc(swaggerOptions)
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(specs))
let {NODE_ENV, MONGODB_URI, SERVER_PORT, PORT} = process.env
mongoose.connect(MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log('DB connected ')
}).catch(err => {
console.log('DB error ' + err)
})
app.use('/', mainRoute)
if (NODE_ENV !== 'test') {
app.listen(PORT || SERVER_PORT, () => {
})
}
module.exports = app