From 8ec5d1608fa10bc1431d6606ed22199df7816e07 Mon Sep 17 00:00:00 2001 From: Phil Rhinehart Date: Mon, 22 Oct 2018 21:11:44 -0500 Subject: [PATCH] Handle next urls for paginated json when host/port/path don't match. Fixed #118 --- package.json | 1 + src/adminApi.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b840870..8392f8a 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/adminApi.js b/src/adminApi.js index d5ec632..a57b6d9 100644 --- a/src/adminApi.js +++ b/src/adminApi.js @@ -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; @@ -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 => { @@ -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)); }); }