Skip to content

Commit

Permalink
fix wrong locale in middleware (#502)
Browse files Browse the repository at this point in the history
* fix locale in middleware

* Create silly-hounds-admire.md
  • Loading branch information
conico974 authored Sep 5, 2024
1 parent f62f538 commit a7540fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/silly-hounds-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"open-next": patch
---

fix wrong locale in middleware
3 changes: 2 additions & 1 deletion packages/open-next/src/core/routing/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function handleMiddleware(
): Promise<MiddlewareOutputEvent | InternalResult> {
const { rawPath, query } = internalEvent;
const normalizedPath = normalizeLocalePath(rawPath);
// We only need the normalizedPath to check if the middleware should run
const hasMatch = middleMatch.some((r) => r.test(normalizedPath));
if (!hasMatch) return internalEvent;
// We bypass the middleware if the request is internal
Expand All @@ -67,7 +68,7 @@ export async function handleMiddleware(
const host = internalEvent.headers.host
? `https://${internalEvent.headers.host}`
: "http://localhost:3000";
const initialUrl = new URL(normalizedPath, host);
const initialUrl = new URL(rawPath, host);
initialUrl.search = convertToQueryString(query);
const url = initialUrl.toString();
// console.log("url", url, normalizedPath);
Expand Down

0 comments on commit a7540fd

Please sign in to comment.