-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (47 loc) · 1.25 KB
/
index.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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const swaggerJsDoc = require('swagger-jsdoc');
const swaggerUI = require('swagger-ui-express');
const path = require('path');
const app = express();
const API = require('./src');
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
const swaggerOptions = {
swaggerDefinition: {
openapi: '3.0.0',
info: {
title: 'API Rest',
description: 'API Rest template.',
contact: {
name: 'Julien G.'
},
},
servers: [{ url: '/api' }],
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
}
}
}
},
apis: ["src/index.js", "src/js/routes/*.route.js", "src/js/routes/*/*.route.js"],
};
const swaggerDocs = swaggerJsDoc(swaggerOptions);
app.use(cors());
app.use('/docs', swaggerUI.serve, swaggerUI.setup(swaggerDocs));
app.use('/api', API);
app.use('/', express.static('public'));
app.get('*', function (request, response) {
response.sendFile(path.resolve(__dirname, 'public', 'index.html'))
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});