Installation
Installing Astro Maintenance v2.0
Section titled “Installing Astro Maintenance v2.0”Version 2.0 brings universal platform support for Node.js, Cloudflare Workers, Vercel, and Netlify! Adding the maintenance page integration to your Astro project is straightforward. Follow these steps to get started quickly.
Universal Platform Support
Section titled “Universal Platform Support”New in v2.0: Enhanced template engine that works identically across all deployment platforms:
- Node.js - Standalone and middleware modes
- Cloudflare Workers - V8 isolates with full edge computing support
- Vercel - Serverless functions and Edge Runtime
- Netlify - CDN-compatible with proper redirects
Live Platform Demos
Section titled “Live Platform Demos”Experience v2.0 in action:
- Vercel: astro-maintenance.vercel.app
- Netlify: astro-maintenance.netlify.app
- Cloudflare: astro-maintenance.alexander-sedeke.workers.dev
Installation
Section titled “Installation”Astro includes an astro add
command to automate the setup of official integrations. If you prefer, you can install integrations manually instead.
To install astro-maintenance
, run the following from your project directory and follow the prompts:
# npmnpm astro add astro-maintenance
# pnpmpnpm astro add astro-maintenance
# yarnyarn astro add astro-maintenance
If you run into any issues, feel free to report them to us on GitHub and try the manual installation steps below.
Manual Install
Section titled “Manual Install”First, install the astro-maintenance
package:
# npmnpm install astro-maintenance
# pnpmpnpm add astro-maintenance
# yarnyarn add astro-maintenance
Then, apply the integration to your astro.config.*
file using the integrations
property:
import { defineConfig } from 'astro/config';import maintenance from 'astro-maintenance';
export default defineConfig({ // ... integrations: [ maintenance({ // your configuration options enabled: true, }), ],});
Basic Setup
Section titled “Basic Setup”Once installed, you need to add the integration to your Astro configuration file:
import { defineConfig } from "astro/config";import maintenance from "astro-maintenance";
export default defineConfig({ integrations: [ maintenance({ enabled: true, // Maintenance mode enabled template: "simple", // Options: 'simple', 'countdown', 'construction' or imported template content title: "Site Under Maintenance", description: "We are performing scheduled maintenance. Please check back soon.", override: "preview", // Access site with ?preview // Other optional parameters... }), ],});
Breaking Changes in v2.0
Section titled “Breaking Changes in v2.0”Custom templates now require ?raw
imports for serverless compatibility:
❌ v1.x (deprecated):
maintenance({ template: "./src/templates/custom.hbs", // No longer supported});
v2.0 (required):
// Import template content using ?rawimport customTemplate from "./src/templates/custom.hbs?raw";
maintenance({ template: customTemplate, // Pass imported content});
Note: All built-in templates (
'simple'
,'countdown'
,'construction'
) work without changes.
Verifying the Installation
Section titled “Verifying the Installation”After configuring the integration, you can verify that it’s working by:
- Setting
enabled: true
in your configuration - Starting your development server or building your site
- Visiting your site - you should see the maintenance page
Temporarily Bypassing Maintenance Mode
Section titled “Temporarily Bypassing Maintenance Mode”If you need to view your site while maintenance mode is active, you can use the override
parameter:
maintenance({ // ... other options override: "preview" // Add this option})
Then access your site by adding ?preview
to the URL, for example:
http://localhost:3000/?preview
Using Environment Variables
Section titled “Using Environment Variables”You can also configure Astro Maintenance using environment variables, which is especially useful for deployment environments where you want to toggle maintenance mode without changing code or rebuilding your application.
Environment variables always take precedence over programmatically defined options. Simply prefix any option with MAINTENANCE_
(in uppercase) to set it via environment variable:
# .env file or environment variablesMAINTENANCE_ENABLED=trueMAINTENANCE_TITLE="We're performing maintenance"MAINTENANCE_TEMPLATE="countdown"MAINTENANCE_COUNTDOWN="2025-12-31T23:59:59"
This makes it easy to:
- Toggle maintenance mode in production without code changes
- Set different configurations for different environments
- Control maintenance mode in CI/CD pipelines
For a complete list of supported environment variables, see the Configuration Options page.
Platform-Specific Notes
Section titled “Platform-Specific Notes”Cloudflare Workers
Section titled “Cloudflare Workers”- ✅ Full compatibility with v2.0’s enhanced template engine
- ✅ No dynamic code evaluation restrictions
- ✅ Edge computing optimized
Vercel
Section titled “Vercel”- ✅ Works with both Serverless Functions and Edge Runtime
- ✅ Optimized template compilation caching
- ✅ Environment variables fully supported
Netlify
Section titled “Netlify”- ✅ CDN-compatible with proper redirects
- ✅ Function-based middleware support
- ✅ Build-time optimizations
Security Tip For security reasons, avoid using a simple or guessable override key like
"preview"
. Instead, use a long, randomly generated, URI-safe string (e.g.,"bypass-43uhksdf82jd82"
) to reduce the risk of unintended access.
Generating a Secure Override Key
Section titled “Generating a Secure Override Key”You can use this command in your terminal to generate a safe random key:
node -e "console.log('bypass-' + require('crypto').randomBytes(12).toString('base64url'))"
Example output:
bypass-jK8dL2t3Y_mkNCxQ9r4Ctg
Use this value as your override
parameter:
maintenance({ // ... other options override: "bypass-jK8dL2t3Y_mkNCxQ9r4Ctg"})
Now you can access your site like this:
http://localhost:3000/?bypass-jK8dL2t3Y_mkNCxQ9r4Ctg
Next Steps
Section titled “Next Steps”Now that you’ve installed Astro Maintenance v2.0, you can:
- Explore the Configuration Options to customize your maintenance page
- Learn about the different Templates available
- Check out the enhanced Custom Templates with v2.0 syntax
- View the Migration Guide for upgrading from v1.x