Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't do permanent redirects in dev mode #12533

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[getsentry/action-github-commit] Auto commit
getsantry[bot] authored Jan 31, 2025
commit 2c921777fff99bf551e9c7c2ae46a5ad0babf14c
6 changes: 4 additions & 2 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -23,14 +23,16 @@ export function middleware(request: NextRequest) {
}

// don't send Permanent Redirects (301) in dev mode - it gets cached for "localhost" by the browser
const redirectStatusCode = process.env.NODE_ENV === 'development' ? 302 : 301
const redirectStatusCode = process.env.NODE_ENV === 'development' ? 302 : 301;

const handleRedirects = (request: NextRequest) => {
const urlPath = request.nextUrl.pathname;

const redirectTo = redirectMap.get(urlPath);
if (redirectTo) {
return NextResponse.redirect(new URL(redirectTo, request.url), {status: redirectStatusCode});
return NextResponse.redirect(new URL(redirectTo, request.url), {
status: redirectStatusCode,
});
}

// If we don't find an exact match, we try to look for a :guide placeholder