@@ -2,8 +2,12 @@ import swaggerJSDoc from 'swagger-jsdoc'
2
2
import swaggerUI from 'swagger-ui-express'
3
3
import fs from 'fs'
4
4
import _path from 'path'
5
+ import { BASE_URL_SERVER } from 'config/baseURL'
6
+ import _ from 'lodash'
5
7
6
- const { APP_NAME , PORT , NODE_ENV } = process . env
8
+ const { APP_NAME , NODE_ENV } = process . env
9
+
10
+ const ENV = NODE_ENV || 'development'
7
11
8
12
const baseRoutes = _path . resolve ( './docs/swagger/routes' )
9
13
// const baseSchemas = _path.resolve('./docs/swagger/schemas')
@@ -29,33 +33,26 @@ const docsSources = getDocs(baseRoutes, getPathRoutes)
29
33
30
34
let baseURLServer = [ ]
31
35
32
- if ( NODE_ENV === 'production ' ) {
36
+ if ( ENV === 'development ' ) {
33
37
baseURLServer = [
34
38
{
35
- url : 'https://api.example.com/v1' ,
36
- description : 'Production server' ,
39
+ url : ` ${ BASE_URL_SERVER } /v1` ,
40
+ description : ` ${ _ . capitalize ( ENV ) } Server` ,
37
41
} ,
38
- ]
39
- } else if ( NODE_ENV === 'staging' ) {
40
- baseURLServer = [
41
42
{
42
43
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' ,
44
49
} ,
45
50
]
46
51
} else {
47
52
baseURLServer = [
48
53
{
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` ,
59
56
} ,
60
57
]
61
58
}
@@ -121,33 +118,26 @@ module.exports = function generateDocs(app) {
121
118
122
119
let swaggerOptURL = [ ]
123
120
124
- if ( NODE_ENV === 'production ' ) {
121
+ if ( ENV === 'development ' ) {
125
122
swaggerOptURL = [
126
123
{
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` ,
129
126
} ,
130
- ]
131
- } else if ( NODE_ENV === 'staging' ) {
132
- swaggerOptURL = [
133
127
{
134
128
url : 'http://api-staging.example.com/v1/api-docs.json' ,
135
129
name : 'Staging Server' ,
136
130
} ,
131
+ {
132
+ url : 'http://api.example.com/v1/api-docs.json' ,
133
+ name : 'Production Server' ,
134
+ } ,
137
135
]
138
136
} else {
139
137
swaggerOptURL = [
140
138
{
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` ,
151
141
} ,
152
142
]
153
143
}
0 commit comments