-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
67 lines (57 loc) · 1.39 KB
/
server.js
File metadata and controls
67 lines (57 loc) · 1.39 KB
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
const express = require('express');
const app = express();
const bodyParser = require('body-parser')
const i18n = require('i18n')
const cors = require("cors");
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
app.use(cors());
app.set('port', process.env.PORT || 3000);
i18n.configure({
locales: ['en', 'es'],
directory: `${__dirname}/locales`,
defaultLocale: 'en',
objectNotation: true
})
app.use(i18n.init)
app.use(
bodyParser.json({
limit: '20mb'
})
)
app.use(
bodyParser.urlencoded({
limit: '20mb',
extended: true
})
)
app.use(require('./app/routes'));
app.listen(app.get('port'));
const swaggerDefinition = {
info: {
title: 'T-Shop',
version: '1.0.0',
description: 'T-Shop endpoints documentation',
},
host: 'localhost:3003',
basePath: '/',
securityDefinitions: {
bearerAuth: {
type: 'apiKey',
name: 'Authorization',
scheme: 'bearer',
in: 'header',
},
},
};
const options = {
swaggerDefinition,
apis: ['./routes/*.js'],
};
const swaggerSpec = swaggerJSDoc(options);
app.get('/swagger.json', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
module.exports = app;