middleware too many redirects
Answered
Northeast Congo Lion posted this in #help-forum
Northeast Congo LionOP
import { NextRequest, NextResponse } from "next/server";
export function middleware(request: NextRequest) {
if(process.env.MAINTENANCE === 'true') {
return NextResponse.redirect(new URL('/maintenance', request.url))
}
return NextResponse.next();
}I got ERR_TOO_MANY_REDIRECTS when MAINTENANCE is true.
Answered by joulev
if process.env.MAINTENANCE === true && request.nextUrl.pathname !== /maintenance
3 Replies
@Northeast Congo Lion js
import { NextRequest, NextResponse } from "next/server";
export function middleware(request: NextRequest) {
if(process.env.MAINTENANCE === 'true') {
return NextResponse.redirect(new URL('/maintenance', request.url))
}
return NextResponse.next();
}
I got **ERR_TOO_MANY_REDIRECTS** when MAINTENANCE is *true*.
if process.env.MAINTENANCE === true && request.nextUrl.pathname !== /maintenance
Answer
Northeast Congo LionOP
Oh sht haha thanks man
Np it’s a common mistake