Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
82 lines (74 loc) · 1.65 KB
/
Copy pathindex.js
File metadata and controls
82 lines (74 loc) · 1.65 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const express = require('express');
const winston = require('winston');
const swaggerUi = require('swagger-ui-express');
require('dotenv').config();
const app = express();
const port = 3500;
const externalHost = process.env.EXTERNAL_HOST || 'http://localhost';
const externalPort = process.env.EXTERNAL_PORT || 9898;
/**
* Configure winston
*/
winston.add(new winston.transports.Console({
level: 'info',
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple(),
),
}));
/**
* Disable the "try it out" button in swagger
*/
const DisableTryItOutPlugin = () => ({
statePlugins: {
spec: {
wrapSelectors: {
allowTryItOutFor: () => () => false,
},
},
},
});
/**
* Swagger options
*/
const options = {
explorer: true,
swaggerOptions: {
plugins: [
DisableTryItOutPlugin,
],
urls: [
{
url: `${externalHost}:${externalPort}/article-swagger.json`,
name: 'Article',
},
{
url: `${externalHost}:${externalPort}/cart-swagger.json`,
name: 'Cart',
},
{
url: `${externalHost}:${externalPort}/auth-swagger.json`,
name: 'Auth',
},
{
url: `${externalHost}:${externalPort}/user-swagger.json`,
name: 'User',
},
],
},
customCss: '.swagger-ui .topbar .link { display: none }',
};
/**
* Swagger documentation
*/
app.use('/documentation', swaggerUi.serve, swaggerUi.setup(null, options));
/**
* Expose swagger static files
*/
app.use(express.static('swagger'));
/**
* Start the server
*/
app.listen(port, () => {
winston.info(`Server is running on: http://localhost:${port}`);
});