Skip to content

Commit

Permalink
fix(redirect): fix dynamic redirects via json
Browse files Browse the repository at this point in the history
fixes #445
  • Loading branch information
tripodsan committed Mar 3, 2021
1 parent bb63659 commit 0f56fa5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/DynamicRedirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
8 changes: 4 additions & 4 deletions test/redirectconfigs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0f56fa5

Please sign in to comment.