Next.js Discord

Discord Forum

middleware too many redirects

Answered
Northeast Congo Lion posted this in #help-forum
Open in Discord
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
View full answer

3 Replies

Answer
Northeast Congo LionOP
Oh sht haha thanks man
Np it’s a common mistake