|
1 | 1 | JsonRoutes.add("get", "api/:id/swagger.json", function (request, response, next) { |
2 | 2 |
|
| 3 | + // Get current API Document ID |
| 4 | + var apiDocumentId = request.params.id; |
| 5 | + |
3 | 6 | // Get basePath for apiUmbrella from Meteor settings file |
4 | 7 | var apiUmbrellaBaseUrl = Meteor.settings.apiUmbrella.baseUrl; |
5 | 8 |
|
6 | | - // Remove trailing slash |
7 | | - apiUmbrellaBaseUrl = apiUmbrellaBaseUrl.replace(/\/$/, ''); |
8 | | - |
9 | 9 | // 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); |
14 | 11 |
|
15 | 12 | // 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; |
17 | 23 |
|
18 | 24 | // Updates values to custom ones |
19 | | - ApiDoc.host = baseURL.hostname(); |
20 | | - ApiDoc.basePath = baseURL.path(); |
| 25 | + apiDoc.host = baseUrl.hostname(); |
| 26 | + apiDoc.basePath = urlPrefix; |
21 | 27 |
|
22 | 28 | // Sends result back to client |
23 | | - JsonRoutes.sendResult(response, 200, ApiDoc); |
| 29 | + JsonRoutes.sendResult(response, 200, apiDoc); |
24 | 30 | }); |
0 commit comments