Skip to content

Commit 3b3c758

Browse files
committed
fix: base url docs swagger
1 parent c3ac57b commit 3b3c758

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

src/utils/GenerateDocs.js

+24-34
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import swaggerJSDoc from 'swagger-jsdoc'
22
import swaggerUI from 'swagger-ui-express'
33
import fs from 'fs'
44
import _path from 'path'
5+
import { BASE_URL_SERVER } from 'config/baseURL'
6+
import _ from 'lodash'
57

6-
const { APP_NAME, PORT, NODE_ENV } = process.env
8+
const { APP_NAME, NODE_ENV } = process.env
9+
10+
const ENV = NODE_ENV || 'development'
711

812
const baseRoutes = _path.resolve('./docs/swagger/routes')
913
// const baseSchemas = _path.resolve('./docs/swagger/schemas')
@@ -29,33 +33,26 @@ const docsSources = getDocs(baseRoutes, getPathRoutes)
2933

3034
let baseURLServer = []
3135

32-
if (NODE_ENV === 'production') {
36+
if (ENV === 'development') {
3337
baseURLServer = [
3438
{
35-
url: 'https://api.example.com/v1',
36-
description: 'Production server',
39+
url: `${BASE_URL_SERVER}/v1`,
40+
description: `${_.capitalize(ENV)} Server`,
3741
},
38-
]
39-
} else if (NODE_ENV === 'staging') {
40-
baseURLServer = [
4142
{
4243
url: 'https://api-staging.example.com/v1',
43-
description: 'Staging server',
44+
description: 'Staging Server',
45+
},
46+
{
47+
url: 'https://api.example.com/v1',
48+
description: 'Production Server',
4449
},
4550
]
4651
} else {
4752
baseURLServer = [
4853
{
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',
54+
url: `${BASE_URL_SERVER}/v1`,
55+
description: `${_.capitalize(ENV)} Server`,
5956
},
6057
]
6158
}
@@ -121,33 +118,26 @@ module.exports = function generateDocs(app) {
121118

122119
let swaggerOptURL = []
123120

124-
if (NODE_ENV === 'production') {
121+
if (ENV === 'development') {
125122
swaggerOptURL = [
126123
{
127-
url: 'http://api.example.com/v1/api-docs.json',
128-
name: 'Production Server',
124+
url: `${BASE_URL_SERVER}/v1/api-docs.json`,
125+
name: `${_.capitalize(ENV)} Server`,
129126
},
130-
]
131-
} else if (NODE_ENV === 'staging') {
132-
swaggerOptURL = [
133127
{
134128
url: 'http://api-staging.example.com/v1/api-docs.json',
135129
name: 'Staging Server',
136130
},
131+
{
132+
url: 'http://api.example.com/v1/api-docs.json',
133+
name: 'Production Server',
134+
},
137135
]
138136
} else {
139137
swaggerOptURL = [
140138
{
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',
139+
url: `${BASE_URL_SERVER}/v1/api-docs.json`,
140+
name: `${_.capitalize(ENV)} Server`,
151141
},
152142
]
153143
}

0 commit comments

Comments
 (0)