Skip to content

Commit 21fd25b

Browse files
committed
Merge pull request #698 from apinf/feature/documentation-basePath-prefix-fix
Feature/documentation basePath prefix fix - closes #694
2 parents 65c09d9 + 975b966 commit 21fd25b

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

server/routes/jsonRoutes.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
JsonRoutes.add("get", "api/:id/swagger.json", function (request, response, next) {
22

3+
// Get current API Document ID
4+
var apiDocumentId = request.params.id;
5+
36
// Get basePath for apiUmbrella from Meteor settings file
47
var apiUmbrellaBaseUrl = Meteor.settings.apiUmbrella.baseUrl;
58

6-
// Remove trailing slash
7-
apiUmbrellaBaseUrl = apiUmbrellaBaseUrl.replace(/\/$/, '');
8-
99
// Parse basePath string to URI obj
10-
var baseURL = new URI(apiUmbrellaBaseUrl);
11-
12-
// Get current id
13-
var id = request.params.id;
10+
var baseUrl = new URI(apiUmbrellaBaseUrl);
1411

1512
// Fetch API Document from mongo collection
16-
var ApiDoc = ApiDocs.findOne(id);
13+
var apiDoc = ApiDocs.findOne(apiDocumentId);
14+
15+
// Get apiBackendId foreign key from documentation object
16+
var apiBackendId = apiDoc.apiBackendId;
17+
18+
// Fetch related apiBackend document
19+
var apiBackend = ApiBackends.findOne(apiBackendId);
20+
21+
// Get apiBackend's frontend prefix
22+
var urlPrefix = apiBackend.url_matches[0].frontend_prefix;
1723

1824
// Updates values to custom ones
19-
ApiDoc.host = baseURL.hostname();
20-
ApiDoc.basePath = baseURL.path();
25+
apiDoc.host = baseUrl.hostname();
26+
apiDoc.basePath = urlPrefix;
2127

2228
// Sends result back to client
23-
JsonRoutes.sendResult(response, 200, ApiDoc);
29+
JsonRoutes.sendResult(response, 200, apiDoc);
2430
});

0 commit comments

Comments
 (0)