Skip to content

Commit

Permalink
Fix custom protocol and host when API has next pages, fixes #118
Browse files Browse the repository at this point in the history
  • Loading branch information
CyExy committed Feb 28, 2018
1 parent f96787c commit 659a891
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 @@ -80,6 +81,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 All @@ -102,7 +110,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 659a891

Please sign in to comment.