Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

hotfix: redirect.added was unreliable espec in tests #130

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/steps/setupRedirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ const setupRedirects = (publishPath) => {
// less-specific routes (e.g., catch-all)
const sortedRoutes = getSortedRoutes(nextRedirects.map(({ route }) => route));

// There may be several redirects with the same route but different targets
const wasRedirectAdded = (redirect) => {
return redirects.find((addedRedirect) => {
const [route, target] = addedRedirect.split(" ");
return redirect.route === route && redirect.target === target;
});
};

// Assemble redirects for each route
sortedRoutes.forEach((route) => {
const nextRedirect = nextRedirects.find(
(redirect) => redirect.route === route && !redirect.added
(redirect) => redirect.route === route && !wasRedirectAdded(redirect)
);

// One route may map to multiple Netlify routes: e.g., catch-all pages
Expand All @@ -60,8 +68,6 @@ const setupRedirects = (publishPath) => {
const redirect = redirectPieces.join(" ").trim();
logItem(redirect);
redirects.push(redirect);
// Enables us to add colliding route redirects
nextRedirect.added = true;
});
});

Expand Down