Skip to content

Commit

Permalink
fix: query params are not being rewritten
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <noreply@github.com>
  • Loading branch information
virtual-designer authored Aug 28, 2024
1 parent 9767336 commit c60b994
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down Expand Up @@ -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.");
}
Expand All @@ -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,
),
);
Expand Down

0 comments on commit c60b994

Please sign in to comment.