Skip to content

Commit 6d0914f

Browse files
committed
fix: base url api docs swagger
1 parent 32fedf1 commit 6d0914f

File tree

1 file changed

+64
-42
lines changed

1 file changed

+64
-42
lines changed

src/utils/GenerateDocs.js

+64-42
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,44 @@ const getDocs = (basePath, getPath) => {
2727
const docsSources = getDocs(baseRoutes, getPathRoutes)
2828
// const docsSchemes = getDocs(baseSchemas, getPathSchemes)
2929

30-
const serverProduction = [
31-
{
32-
url: 'https://api.example.com/v1',
33-
description: 'Production server',
34-
},
35-
]
30+
let baseURLServer = []
3631

37-
const serverLocal = [
38-
{
39-
url: `http://localhost:${PORT || 8000}/v1`,
40-
description: 'Development server',
41-
},
42-
{
43-
url: 'https://api-staging.example.com/v1',
44-
description: 'Staging server',
45-
},
46-
{
47-
url: 'https://api.example.com/v1',
48-
description: 'Production server',
49-
},
50-
]
32+
if (NODE_ENV === 'production') {
33+
baseURLServer = [
34+
{
35+
url: 'https://api.example.com/v1',
36+
description: 'Production server',
37+
},
38+
]
39+
} else if (NODE_ENV === 'staging') {
40+
baseURLServer = [
41+
{
42+
url: 'https://api-staging.example.com/v1',
43+
description: 'Staging server',
44+
},
45+
]
46+
} else {
47+
baseURLServer = [
48+
{
49+
url: `http://localhost:${PORT || 8000}/v1`,
50+
description: 'Development server',
51+
},
52+
{
53+
url: 'https://api-staging.example.com/v1',
54+
description: 'Staging server',
55+
},
56+
{
57+
url: 'https://api.example.com/v1',
58+
description: 'Production server',
59+
},
60+
]
61+
}
5162

5263
module.exports = function generateDocs(app) {
5364
const swaggerOptions = {
5465
definition: {
5566
openapi: '3.0.1',
56-
servers: NODE_ENV === 'production' ? serverProduction : serverLocal,
67+
servers: baseURLServer,
5768
// security: [ //Set GLOBAL
5869
// {
5970
// auth_token: []
@@ -108,33 +119,44 @@ module.exports = function generateDocs(app) {
108119
apis: [],
109120
}
110121

111-
const swaggerOptProduction = [
112-
{
113-
url: 'http://api.example.com/v1/api-docs.json',
114-
name: 'Production Server',
115-
},
116-
]
122+
let swaggerOptURL = []
117123

118-
const swaggerOptLocal = [
119-
{
120-
url: `http://localhost:${PORT || 8000}/v1/api-docs.json`,
121-
name: 'Development Server',
122-
},
123-
{
124-
url: 'http://api-staging.example.com/v1/api-docs.json',
125-
name: 'Staging Server',
126-
},
127-
{
128-
url: 'http://api.example.com/v1/api-docs.json',
129-
name: 'Production Server',
130-
},
131-
]
124+
if (NODE_ENV === 'production') {
125+
swaggerOptURL = [
126+
{
127+
url: 'http://api.example.com/v1/api-docs.json',
128+
name: 'Production Server',
129+
},
130+
]
131+
} else if (NODE_ENV === 'staging') {
132+
swaggerOptURL = [
133+
{
134+
url: 'http://api-staging.example.com/v1/api-docs.json',
135+
name: 'Staging Server',
136+
},
137+
]
138+
} else {
139+
swaggerOptURL = [
140+
{
141+
url: `http://localhost:${PORT || 8000}/v1/api-docs.json`,
142+
name: 'Development Server',
143+
},
144+
{
145+
url: 'http://api-staging.example.com/v1/api-docs.json',
146+
name: 'Staging Server',
147+
},
148+
{
149+
url: 'http://api.example.com/v1/api-docs.json',
150+
name: 'Production Server',
151+
},
152+
]
153+
}
132154

133155
const swaggerSpec = swaggerJSDoc(swaggerOptions)
134156
const optionsSwaggerUI = {
135157
explorer: true,
136158
swaggerOptions: {
137-
urls: NODE_ENV === 'production' ? swaggerOptProduction : swaggerOptLocal,
159+
urls: swaggerOptURL,
138160
},
139161
}
140162

0 commit comments

Comments
 (0)