Skip to content

Commit

Permalink
Fix redirect to right page for content redirects (#2241)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse authored Mar 26, 2024
1 parent 0ddbe5c commit 4be6ead
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,19 +570,25 @@ async function lookupSpaceByAPI(

if ('redirect' in data) {
if (alternative.primary) {
// Append the path to the redirect URL if it's a VA redirect
// Append the path to the redirect URL
// 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,
),
);
if (data.target === 'content') {
const redirect = new URL(data.redirect);
redirect.pathname = joinPath(redirect.pathname, alternative.extraPath);
data.redirect = redirect.toString();
} else {
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();
}
}
}

Expand Down

0 comments on commit 4be6ead

Please sign in to comment.