diff --git a/src/DynamicRedirect.js b/src/DynamicRedirect.js index 693dbd08..38b8eb51 100644 --- a/src/DynamicRedirect.js +++ b/src/DynamicRedirect.js @@ -82,8 +82,13 @@ class DynamicRedirect { }); const text = await res.text(); if (res.ok) { - this._data = JSON.parse(text).map(clean); + this._data = JSON.parse(text); + if ('data' in this._data) { + this._data = this._data.data; + } + this._data = this._data.map(clean); } + this._logger.info(`loaded lookup table from ${this._src}`); } catch (e) { this._logger.warn(`failed to get ${this._src} ${e.message}`); } diff --git a/test/redirectconfigs.test.js b/test/redirectconfigs.test.js index 695ac5e5..d77b145e 100644 --- a/test/redirectconfigs.test.js +++ b/test/redirectconfigs.test.js @@ -88,12 +88,12 @@ describe('Redirects Config Loading (from GitHub)', () => { server.get('https://helix-demo--adobe.hlx.page/redirects.json').intercept((req, res) => { assert.equal(req.headers['x-request-id'], 'random'); - return res.status(200).json([ - { + return res.status(200).json({ + data: [{ from: '/en/old', to: '/en/new', - }, - ]); + }], + }); }); const config = await new RedirectConfig()