fix maintenance layout

This commit is contained in:
Abhishek Kumar 2026-02-05 21:35:27 +05:30
parent 50c2c17c5b
commit 7b297c53c8
2 changed files with 40 additions and 18 deletions

View file

@ -35,6 +35,7 @@ export default function RootLayout({
}: {
children: React.ReactNode
}) {
const isMaintenanceMode = process.env.MAINTENANCE_MODE === 'true';
return (
<html lang="en" suppressHydrationWarning>
@ -59,22 +60,26 @@ export default function RootLayout({
</head>
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}>
<AuthProvider>
<AppConfigProvider>
<Suspense fallback={<SpinLoader />}>
<UserConfigProvider>
<OnboardingProvider>
<PostHogIdentify />
<AppLayout>
{children}
</AppLayout>
<Toaster />
<ChatwootWidget />
</OnboardingProvider>
</UserConfigProvider>
</Suspense>
</AppConfigProvider>
</AuthProvider>
{isMaintenanceMode ? (
children
) : (
<AuthProvider>
<AppConfigProvider>
<Suspense fallback={<SpinLoader />}>
<UserConfigProvider>
<OnboardingProvider>
<PostHogIdentify />
<AppLayout>
{children}
</AppLayout>
<Toaster />
<ChatwootWidget />
</OnboardingProvider>
</UserConfigProvider>
</Suspense>
</AppConfigProvider>
</AuthProvider>
)}
</body>
</html>
);

View file

@ -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).*)',
],
};