Next.js Discord

Discord Forum

NextResponse.redirect infinite loop

Unanswered
Entlebucher Mountain Dog posted this in #help-forum
Open in Discord
Entlebucher Mountain DogOP
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { endDate } from './constants';

export function middleware(req: NextRequest) {
const isDateEnded = endDate < new Date()
if (!isDateEnded) {
// after redirecting my /launch page is not found but still my page is found
// how can i fix it without changing the url
return NextResponse.redirect(new URL("/launch", req.url));
}
return NextResponse.next();
}

export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|icon.ico).*)"],
}

2 Replies