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 mode

Implementation 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&apos;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

  1. Log into your deployment platform (Vercel, etc.)
  2. Set MAINTENANCE_MODE=true in your environment variables
  3. Deploy or restart the application
  4. When the emergency is resolved, set MAINTENANCE_MODE=false

For Planned Maintenance

  1. Announce the maintenance window to users in advance
  2. Set MAINTENANCE_MODE=true when you're ready to start maintenance
  3. Perform required updates, database migrations, etc.
  4. Test the changes in a staging environment
  5. Set MAINTENANCE_MODE=false to bring the site back online
  6. Monitor for any issues

Testing Maintenance Mode

Before using maintenance mode in production:

  1. Test locally by setting MAINTENANCE_MODE=true in your .env file
  2. Restart your development server to see the maintenance page
  3. 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