Skip to content

Commit

Permalink
Merge pull request #12331 from ethereum/master
Browse files Browse the repository at this point in the history
Master -> staging
  • Loading branch information
corwintines authored Mar 1, 2024
2 parents fec13bb + af37d6a commit 3c29e40
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ export async function middleware(req: NextRequest) {
}

if (req.nextUrl.locale === FAKE_LOCALE) {
// Apparently `localeDetection` does not work when using the faked locale
// hack. So, detect the locale manually
// Apparently, the built-in `localeDetection`from Next does not work when
// using the faked locale hack. So, we need to detect the locale manually
const localeDetected = detectLocale(req.headers.get("accept-language"))
const locale = localeDetected || DEFAULT_LOCALE

return NextResponse.redirect(
new URL(`/${locale}${req.nextUrl.pathname}`, req.url),
{ status: 301 }
)
const redirectUrl = new URL(`/${locale}${req.nextUrl.pathname}`, req.url)

// Add trailing slash if it's not present
if (!redirectUrl.pathname.endsWith("/")) {
redirectUrl.pathname = redirectUrl.pathname + "/"
}

return NextResponse.redirect(redirectUrl, { status: 301 })
}
}

0 comments on commit 3c29e40

Please sign in to comment.