Skip to content

Commit

Permalink
πŸ› Verify host before redirect #2619 (#2620)
Browse files Browse the repository at this point in the history
* πŸ›  Verify host before redirect #2619

* ✏️ logic adjustment #2619

* Add localhost #2619

* ✏️ logic adjustment #2619
  • Loading branch information
millianapia authored Oct 31, 2024
1 parent ef1ac68 commit 6e84c26
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions web/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ export async function middleware(request: NextRequest) {
return NextResponse.redirect(dnsRedirect, PERMANENT_REDIRECT)
}

// Check if it is a WWW redirect
const wwwRedirect = getWWWRedirect(host, pathname)
if (wwwRedirect) {
return NextResponse.redirect(wwwRedirect, PERMANENT_REDIRECT)
// Skip WWW redirect for Radix URLs and localhost
if (
host !== process.env.RADIX_PUBLIC_DOMAIN_NAME &&
host !== process.env.RADIX_CANONICAL_DOMAIN_NAME &&
host !== 'localhost:3000'
) {
const wwwRedirect = getWWWRedirect(host, pathname)
if (wwwRedirect) {
return NextResponse.redirect(wwwRedirect, PERMANENT_REDIRECT)
}
}

// Redirect external links to news which is now archived if link doesn't exist in Sanity
Expand Down

0 comments on commit 6e84c26

Please sign in to comment.