From 7b297c53c8f2d39876e57b08defe041a326b5a1b Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 5 Feb 2026 21:35:27 +0530 Subject: [PATCH] fix maintenance layout --- ui/src/app/layout.tsx | 37 +++++++++++++++++++++---------------- ui/src/middleware.ts | 21 +++++++++++++++++++-- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/ui/src/app/layout.tsx b/ui/src/app/layout.tsx index 060fdd3..c63003a 100644 --- a/ui/src/app/layout.tsx +++ b/ui/src/app/layout.tsx @@ -35,6 +35,7 @@ export default function RootLayout({ }: { children: React.ReactNode }) { + const isMaintenanceMode = process.env.MAINTENANCE_MODE === 'true'; return ( @@ -59,22 +60,26 @@ export default function RootLayout({ - - - }> - - - - - {children} - - - - - - - - + {isMaintenanceMode ? ( + children + ) : ( + + + }> + + + + + {children} + + + + + + + + + )} ); diff --git a/ui/src/middleware.ts b/ui/src/middleware.ts index b184353..2a8b94b 100644 --- a/ui/src/middleware.ts +++ b/ui/src/middleware.ts @@ -18,10 +18,28 @@ export function middleware(request: NextRequest) { return NextResponse.next(); } + // Return 503 for API routes during maintenance + if (request.nextUrl.pathname.startsWith('/api')) { + return NextResponse.json( + { + error: 'Service Unavailable', + message: + process.env.MAINTENANCE_MESSAGE || + 'We are currently performing scheduled maintenance. Please try again later.', + }, + { status: 503 } + ); + } + // Redirect all other requests to maintenance page return NextResponse.redirect(new URL('/maintenance', request.url)); } + // Skip OSS token handling for API routes + if (request.nextUrl.pathname.startsWith('/api')) { + return NextResponse.next(); + } + const authProvider = process.env.NEXT_PUBLIC_AUTH_PROVIDER || 'stack'; // Only handle OSS mode @@ -68,12 +86,11 @@ export const config = { matcher: [ /* * Match all request paths except: - * - api routes * - _next/static (static files) * - _next/image (image optimization files) * - favicon.ico (favicon file) * - public files (public folder) */ - '/((?!api|_next/static|_next/image|favicon.ico|public).*)', + '/((?!_next/static|_next/image|favicon.ico|public).*)', ], };