Skip to content

Commit

Permalink
Fix custom protocol and host when API has next pages, fixes mybuilder…
Browse files Browse the repository at this point in the history
  • Loading branch information
CyExy authored and dvogel committed Dec 20, 2018
1 parent a9e7e27 commit c7bf69a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/adminApi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import createRouter from './router';
import requester from './requester';
import { parseVersion } from './utils.js'
import url from 'url';

let pluginSchemasCache;
let kongVersionCache;
Expand Down Expand Up @@ -85,6 +86,13 @@ function getPluginScheme(plugin, schemaRoute) {
.then(({fields}) => [plugin, fields]);
}

function fixNext(uri, nextUri) {
const { protocol, auth, host, hostname, port } = url.parse(uri);
const { hash, search, query, pathname, path } = url.parse(nextUri);

return url.format({ protocol, auth, hostname, port, hash, search, query, pathname, path });
}

function getPaginatedJson(uri) {
return requester.get(uri)
.then(response => {
Expand Down Expand Up @@ -115,7 +123,7 @@ function getPaginatedJson(uri) {
return json.data;
}

return getPaginatedJson(json.next).then(data => json.data.concat(data));
return getPaginatedJson(fixNext(json.next)).then(data => json.data.concat(data));
});
}

Expand Down

0 comments on commit c7bf69a

Please sign in to comment.