-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
67 lines (58 loc) · 1.55 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
64
65
66
67
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const swaggerUI = require('swagger-ui-express');
const Cors = require('cors');
const swaggerJsDoc = require('swagger-jsdoc');
const dbConnection = require('./configs/db.config');
const app = express();
const routes = require('./routes')
require('./auth/auth');
const connectToMongo = async () => await dbConnection()
connectToMongo();
const swaggerOptions = {
swaggerDefinition: {
info: {
title: 'Title Project',
description: 'Description Project',
contact: {
name: 'Carlos Ziegler'
},
servers: ['http://localhost:3000']
}
},
apis: ["routes.js"]
}
const swaggerDocs = swaggerJsDoc(swaggerOptions)
const DisableTryItOutPlugin = function () {
return {
statePlugins: {
spec: {
wrapSelectors: {
allowTryItOutFor: () => () => false
}
}
}
}
}
const options = {
swaggerOptions: {
plugins: [
DisableTryItOutPlugin
]
}
};
app.use(Cors())
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.json())
app.use(routes)
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocs, options))
//Handle errors
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.json({ error: err });
});
app.listen(process.env.PORT || 3000, () => {
console.log('Server started')
});