From 24f8afd32855e158379098069d1660b43577618c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 26 Mar 2024 11:36:01 +0100 Subject: [PATCH] Fix VA redirects for nested paths --- src/middleware.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/middleware.ts b/src/middleware.ts index c9d6e51648..3e0d831781 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -569,7 +569,20 @@ 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 + 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; }