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 authored and Kalil Smith-Nuevelle committed Dec 20, 2018
1 parent a9e7e27 commit 8ec5d16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"prettyjson": "^1.1.3",
"semver": "^5.5.0",
"socks-proxy-agent": "^4.0.1",
"url": "^0.11.0",
"uuid": "^3.2.1"
},
"devDependencies": {
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 @@ -85,6 +86,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 @@ -115,7 +123,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 8ec5d16

Please sign in to comment.