From c7bf69adbcd855136eeec149c78e99e32fe88381 Mon Sep 17 00:00:00 2001 From: Sten Hiedel Date: Wed, 28 Feb 2018 22:54:20 +0000 Subject: [PATCH] Fix custom protocol and host when API has next pages, fixes #118 --- src/adminApi.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/adminApi.js b/src/adminApi.js index d5ec632..2b6156a 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 url from 'url'; let pluginSchemasCache; let kongVersionCache; @@ -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 => { @@ -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)); }); }