C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • Cluster Mode
  • Microservices
  • Observability
  • Security Layers
  • Universal Signals
  • Canx Flow
  • Maintenance
v1.6.2
Enterprise

Maintenance Mode

Put your application into maintenance mode during deployments.

# Overview

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.

# CLI Commands

Enable Maintenance Mode

# Basic usage
canx down
# With custom message
canx down --message="Upgrading to v2.0"
# With secret bypass
canx down --secret="my-secret-key"
# With retry header
canx down --retry=60

Disable Maintenance Mode

canx up

# Options

OptionDescription
--messageCustom maintenance message
--secretSecret key to bypass maintenance mode
--retryRetry-After header value in seconds
--refreshAuto-refresh interval in seconds
--redirectRedirect to a custom URL
--exceptURIs to bypass (comma-separated)

# Middleware

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

# Programmatic Usage

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');
}

# Bypassing Maintenance Mode

When you set a secret key, you can bypass maintenance mode by adding a query parameter:

https://yoursite.com?_maintenance_secret=your-secret

After bypassing, a cookie will be set so you don't need to add the query parameter again.