Skip to content

Commit

Permalink
Handle next urls for paginated json when host/port/path don't match. F…
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Rhinehart committed Oct 23, 2018
1 parent 3c9d032 commit 68d5ce6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"object-assign": "^4.0.1",
"pad": "^2.0.3",
"prettyjson": "^1.1.3",
"semver": "^5.5.0"
"semver": "^5.5.0",
"url": "^0.11.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
Expand Down
12 changes: 10 additions & 2 deletions 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 { parseVersion } from './utils.js';
import { parse, format } from 'url';

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

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

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

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

return getPaginatedJson(json.next).then(data => json.data.concat(data));
return getPaginatedJson(fixNextUri(uri, json.next)).then(data => json.data.concat(data));
});
}

Expand Down

0 comments on commit 68d5ce6

Please sign in to comment.