forked from berbinarbinar/binar-challenge-chapter-8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (52 loc) · 1.34 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
const express = require('express')
const app = express()
const cors = require('cors')
const apiRouter = require('./server/routes')
const errorHandler = require('./server/middlewares/errorHandler')
const PORT = process.env.PORT || 4000
const swaggerUi = require("swagger-ui-express")
const swaggerJsDoc = require("swagger-jsdoc")
// middlewares
app.use(cors())
app.use(express.urlencoded({extended: true}))
app.use(express.json())
app.use(errorHandler)
const swaggerOptions = {
swaggerDefinition: {
openapi: '3.0.3',
info: {
title: 'Binar Academy Chapter 8',
version: '1.0.0',
description: 'API doc for Binar challenge Chapter 8',
contact: {
name: 'Kelvin Handoko'
},
servers: {
url: `http://localhost:${process.env.PORT}`,
description: 'development server'
}
}
},
apis: ['app.js', './server/**/*.js']
}
const swaggerDocs = swaggerJsDoc(swaggerOptions);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs))
/**
* @Routes /api
* entrypoint for all API routes
*/
/**
* @swagger
* /api/v1:
* get:
* description: Use to be the entrypoint for /api/v1
* responses:
* 200:
* description: test
* post:
* description: use to be post
*/
app.use("/api", apiRouter)
app.listen(PORT, () => {
console.log(`Listening on http://localhost:${PORT}`)
})