-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (39 loc) · 1.16 KB
/
Copy pathserver.js
File metadata and controls
44 lines (39 loc) · 1.16 KB
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
43
44
const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const dotenv=require('dotenv')
const envFile = process.env.NODE_ENV ? `.env.${process.env.NODE_ENV}` : '.env'
dotenv.config({ path: envFile })
//setting up swagger documentation for APIs. Accessible at /docs path.
const swaggerUi = require('swagger-ui-express')
const swaggerJsdoc = require('swagger-jsdoc')
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'API Documentation',
version: '1.0.0'
}
},
apis: ['./controllers/*.js']
}
const optionsCSSSwagger = {
customCss: '.swagger-ui .topbar { display: none }'
}
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
const swaggerSpec = swaggerJsdoc(options)
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec, optionsCSSSwagger))
// connecting to mongodb
mongoose.connect(process.env.MONGODB_URL)
.then(() => {
console.log('Connected to db')
})
.catch((err) => {
console.log('Error connecting to db:', err)
})
// getting the routes
const routes = require('./routes')
app.use(routes)
module.exports=app