-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (53 loc) · 1.4 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import express from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import morgan from 'morgan'
import connectToDb from './libs/db/mongoose.js'
import swaggerUI from 'swagger-ui-express'
import swaggerJsDoc from 'swagger-jsdoc'
import coffeeRouter from './routes/coffee.route.js'
const PORT = process.env.PORT || 4000
connectToDb()
const app = express()
app.use(cors())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json({ type: 'application/json' }))
const options = {
definition: {
openapi: '3.0.0',
info: {
contact: {
email: 'me@damlakoksal.com',
name: 'Damla Koksal'
},
description: 'Coffee endpoint API',
title: 'Coffee API',
version: '0.0.1'
},
servers: [
// {
// url: 'http://localhost:4000'
// }
{
url: '{server}',
variables: {
server: {
default: 'https://starducks-mongodb-server.herokuapp.com/'
}
}
}
]
},
apis: ['./routes/*.route.js']
}
const specs = swaggerJsDoc(options)
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(specs))
app.use(express.json())
app.use(morgan('dev'))
app.use('/coffee', coffeeRouter)
app.listen(PORT, () =>
console.log(
`✅ The server is running on: http://localhost:${PORT}\n📄 Swagger Documentation: http://localhost:${PORT}/api-docs`
)
)
export default app