Put your application into maintenance mode during deployments.
CanxJS provides a simple way to put your application into maintenance mode. When in maintenance mode, all requests will receive a 503 (Service Unavailable) response with a customizable maintenance page.
| Option | Description |
|---|---|
| --message | Custom maintenance message |
| --secret | Secret key to bypass maintenance mode |
| --retry | Retry-After header value in seconds |
| --refresh | Auto-refresh interval in seconds |
| --redirect | Redirect to a custom URL |
| --except | URIs to bypass (comma-separated) |
Add the maintenance middleware to check for maintenance mode in your application:
import { maintenanceMiddleware } from 'canxjs';
const app = createApp({
middlewares: [
maintenanceMiddleware({
// Optional: Custom render function
render: (req, data) => {
return new Response('Custom maintenance page', { status: 503 });
},
// Optional: URIs to bypass
except: ['/api/health', '/api/status'],
}),
],
});import {
maintenance,
isDownForMaintenance,
preCheckMaintenance
} from 'canxjs';
// Check if in maintenance mode
if (isDownForMaintenance()) {
console.log('App is in maintenance mode');
}
// Get maintenance data
const data = maintenance().getData();
console.log(data?.message);
// Programmatically enable/disable
maintenance().activate({ message: 'Upgrading...' });
maintenance().deactivate();
// Pre-check (before app boots)
if (preCheckMaintenance()) {
console.log('Skipping full app boot');
}When you set a secret key, you can bypass maintenance mode by adding a query parameter:
After bypassing, a cookie will be set so you don't need to add the query parameter again.