This project now supports a Maintenance Mode feature, allowing the API to return HTTP 503 Service Unavailable during upgrades or maintenance windows.
- Toggle Location: The maintenance flag is controlled via the
MAINTENANCE_MODEenvironment variable in the.envfile. - Behavior:
- When
MAINTENANCE_MODE=true, all API endpoints (except those explicitly allowlisted) will return a 503 status with a maintenance message. - When
MAINTENANCE_MODE=false, the API operates normally.
- When
- Middleware: A new middleware (
maintenanceMiddleware.ts) checks the flag and enforces maintenance mode. - Allowlist: Health check and status endpoints are allowlisted and remain accessible during maintenance.
- Enable Maintenance Mode:
- Set
MAINTENANCE_MODE=truein the.envfile. - Restart the server (if using process.env directly).
- Set
- Disable Maintenance Mode:
- Set
MAINTENANCE_MODE=falsein the.envfile. - Restart the server.
- Set
/status/health(if present)
- To make the flag dynamic (e.g., toggle via DB or admin API), refactor the middleware to check the DB or cache instead of process.env.
- To allow more endpoints, add their paths to the allowlist in the middleware.
- With maintenance mode enabled, all non-allowlisted endpoints should return 503.
- With maintenance mode disabled, all endpoints should function normally.
.env(added/updated)src/middleware/maintenanceMiddleware.ts(added)src/app.tsorsrc/index.ts(middleware integrated)MAINTENANCE_MODE.md(this documentation)
For further customization or questions, see the comments in the middleware or contact the maintainers.