From c60b99419c26962f41911b98c22fd3c9ff0fe826 Mon Sep 17 00:00:00 2001 From: Ar Rakin <68149013+virtual-designer@users.noreply.github.com> Date: Wed, 28 Aug 2024 07:35:53 +0000 Subject: [PATCH] fix: query params are not being rewritten Signed-off-by: GitHub --- src/middleware.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index 22e43e1..c30c8ce 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -17,10 +17,8 @@ const FRONTEND_DOMAIN = process.env.NEXT_PUBLIC_FRONTEND_DOMAIN!.replace( "", ); -const FRONTEND_ROOT_DOMAIN = process.env.NEXT_PUBLIC_FRONTEND_ROOT_DOMAIN!.replace( - /:\d+$/, - "", -); +const FRONTEND_ROOT_DOMAIN = + process.env.NEXT_PUBLIC_FRONTEND_ROOT_DOMAIN!.replace(/:\d+$/, ""); function error(status: number, message: string) { const [hostname, port] = @@ -88,7 +86,8 @@ export function middleware(request: NextRequest) { if ( !hostname || (!hostname.endsWith("." + FRONTEND_ROOT_DOMAIN) && - hostname !== FRONTEND_DOMAIN && hostname !== FRONTEND_ROOT_DOMAIN) + hostname !== FRONTEND_DOMAIN && + hostname !== FRONTEND_ROOT_DOMAIN) ) { return error(400, "The request hostname is not valid."); } @@ -115,7 +114,9 @@ export function middleware(request: NextRequest) { if (subdomainConfig.rewrite) { return NextResponse.rewrite( new URL( - subdomainConfig.rewrite.replace("%URI%", nextUrl.pathname), + subdomainConfig.rewrite.replace("%URI%", nextUrl.pathname) + + (request.nextUrl.search ? "?" : "") + + request.nextUrl.searchParams.toString(), request.url, ), );