Docs
Maintenance Mode
Maintenance Mode
Learn how to use the maintenance mode feature to take the site offline during updates or emergencies.
Maintenance Mode
VidsGenius includes a maintenance mode feature that allows you to take the entire site offline during planned updates or emergency situations.
Overview
When maintenance mode is activated:
- All incoming requests are intercepted by the Next.js middleware
- Users see a simple maintenance page with HTTP status code 503
- No application code beyond the middleware is executed
- API routes are also unavailable
Configuration
Maintenance mode is controlled by the MAINTENANCE_MODE environment variable:
# In .env or deployment environment variables
MAINTENANCE_MODE=false # Default: site is online
MAINTENANCE_MODE=true # Site is offline in maintenance modeImplementation Details
The maintenance mode check is implemented at the very beginning of the middleware flow in middleware.ts:
// First check for maintenance mode
if (process.env.MAINTENANCE_MODE === "true") {
return new NextResponse(
`<!DOCTYPE html><html><head><title>Under Maintenance</title>
<meta name="viewport" content="width=device-width,initial-scale=1"></head>
<body style="display:flex;align-items:center;justify-content:center;min-height:100vh;">
<div style="text-align:center"><h1 style="font-size:2rem;font-weight:bold;">
Under Maintenance</h1><p>We'll be back soon!</p></div></body></html>`,
{
status: 503,
headers: { "content-type": "text/html" },
}
);
}This intercepts all requests before any other middleware processing, including authentication.
Usage Guide
For Emergency Situations
- Log into your deployment platform (Vercel, etc.)
- Set
MAINTENANCE_MODE=truein your environment variables - Deploy or restart the application
- When the emergency is resolved, set
MAINTENANCE_MODE=false
For Planned Maintenance
- Announce the maintenance window to users in advance
- Set
MAINTENANCE_MODE=truewhen you're ready to start maintenance - Perform required updates, database migrations, etc.
- Test the changes in a staging environment
- Set
MAINTENANCE_MODE=falseto bring the site back online - Monitor for any issues
Testing Maintenance Mode
Before using maintenance mode in production:
- Test locally by setting
MAINTENANCE_MODE=truein your.envfile - Restart your development server to see the maintenance page
- Test in your staging environment before using in production
Best Practices
- Communicate with users: Send emails or notifications about planned maintenance
- Choose low-traffic times: Schedule maintenance during periods of lowest user activity
- Be quick: Keep maintenance windows as short as possible
- Have a rollback plan: Be prepared to restore previous state if needed
- Monitor after maintenance: Watch for any issues after bringing the site back online