-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
71 lines (64 loc) · 1.47 KB
/
server.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
64
65
66
67
68
69
70
71
const express = require('express');
const swaggerJsDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
/**
* Swagger and OpenAPI
*/
const swaggerDoc = swaggerJsDoc({
definition: {
openapi: "3.0.3",
info: {
title: "Bonbon API",
version: "1.0.0",
description: "API for the Bonbon app",
},
servers: [
{
url: "http://localhost:3000"
}
],
components: {
schemas: {
APIError: {
type: "object",
properties: {
message: {
type: "string"
},
}
}
}
}
},
apis: [
"./api/controllers/*.js",
"./api/models/*.js"
]
});
/**
* Database connection
*/
require("./api/models/dbConn.js");
/**
* Create server
*/
const port = process.env.PORT || 3000;
const app = express();
/**
* Configure server
*/
const apiRouter = require("./api/routes/router.js");
app.use("/api", apiRouter);
// swagger.json
apiRouter.get("/swagger.json", (req, res) => {
res.status(200).json(swaggerDoc);
});
// docs
apiRouter.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDoc));
/**
* Start server
*/
app.listen(port, () => {
console.log(`Server is listening on port ${port}, running in ${
process.env.NODE_ENV} mode`);
});