-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (32 loc) · 1.06 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
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const swaggerUi = require('swagger-ui-express');
const swaggerJsdoc = require('swagger-jsdoc');
require('dotenv').config();
const { postRouter } = require('./routes/postRoutes');
const { commentRouter } = require('./routes/commentRoutes');
const { userRouter } = require('./routes/userRoutes');
const { bookRouter } = require('./routes/bookRoutes');
const openapiSpecification = swaggerJsdoc({
definition: {
openapi: '3.0.0',
info: {
version: '1.0.0',
},
},
apis: ['./routes/*.js'],
});
const PORT = process.env.PORT || 8080;
const app = express();
app.use(bodyParser.json());
app.use(cors());
app.use('/api-v1/', express.static('public/'));
app.use('/api-v1/doc', swaggerUi.serve, swaggerUi.setup(openapiSpecification));
app.use('/api-v1', postRouter);
app.use('/api-v1/post', commentRouter);
app.use('/api-v1/user', userRouter);
app.use('/api-v1', bookRouter);
app.listen(PORT, () => {
console.log(`My server started on port ${PORT}`);
});