Skip to content

Commit

Permalink
Fix VA redirects for nested paths (#2236)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse authored Mar 26, 2024
1 parent 0d99906 commit ee7a74f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,23 @@ async function lookupSpaceByAPI(
}

if ('redirect' in data) {
if (alternative.url === url.toString()) {
if (alternative.primary) {
// Append the path to the redirect URL if it's a VA redirect
// because we might have matched a shorter path and the redirect is relative to it
if (alternative.extraPath) {
const redirect = new URL(data.redirect);
if (redirect.searchParams.has('location')) {
redirect.searchParams.set(
'location',
joinPath(
redirect.searchParams.get('location') ?? '',
alternative.extraPath,
),
);
data.redirect = redirect.toString();
}
}

return data;
}

Expand Down

0 comments on commit ee7a74f

Please sign in to comment.