Add detailed documentation for multiple API endpoints and features: - User playlists API with sharing and cloning endpoints - Shared playlists API with access token generation - Community playlists API for browsing/downloading - Downloads API with SSE progress tracking - Jobs API for scheduled task management - Maintenance mode feature documentation Update existing docs: - Clarify Flashpoint vs User playlists distinction - Add setup-status, most-played, and theme endpoints - Expand settings cache and permission cache docs - Reorganize API reference navigation structure
5.3 KiB
Maintenance Mode
Temporarily restrict access to the application while performing system updates.
Overview
Maintenance mode allows administrators to temporarily block access to the application while performing critical operations like database migrations, updates, or emergency repairs. When enabled, only administrators can access the system while regular users and guests receive a maintenance message.
How It Works
When maintenance mode is enabled:
- Administrators (users with
settings.updatepermission) can access everything - Regular users are blocked from all API endpoints
- Guest users are blocked from all API endpoints
- Public paths remain accessible for login (so admins can authenticate)
Enabling Maintenance Mode
Via Settings UI
- Navigate to Settings → App Settings (requires admin access)
- Toggle Maintenance Mode on
- Confirm the change
Via API
curl -X PATCH http://localhost:3100/api/settings/app \
-H "Authorization: Bearer <admin-token>" \
-H "Content-Type: application/json" \
-d '{"maintenanceMode": true}'
Via Database (Emergency)
If locked out, update the database directly:
UPDATE system_settings
SET value = '0'
WHERE key = 'app.maintenance_mode';
User Experience
Admin Users
Admins experience no change during maintenance:
- Full access to all features
- Can browse games, manage users, update settings
- Log entries show admin activity during maintenance
Non-Admin Users
When a non-admin user tries to access the site:
API Response:
{
"error": "Service Unavailable",
"message": "The application is currently undergoing maintenance. Please try again later.",
"maintenanceMode": true,
"retryAfter": 3600
}
HTTP Status: 503 Service Unavailable
Headers:
Retry-After: 3600(suggests retry after 1 hour)
Frontend Handling
The frontend should:
- Detect 503 responses with
maintenanceMode: true - Display a maintenance message to users
- Provide a way to check if maintenance has ended
Public Paths
These endpoints remain accessible during maintenance (for admin login):
| Path | Purpose |
|---|---|
/health |
Health check endpoint |
/api/auth/login |
Admin authentication |
/api/auth/register |
User registration |
/api/auth/setup-status |
Initial setup check |
/api/auth/refresh |
Token refresh |
/api/settings/public |
Public settings (UI needs) |
/api/playlists/shared/* |
Shared playlist access |
Security
Fail-Closed Strategy
If the maintenance middleware encounters an error (e.g., database failure), it blocks requests rather than allowing them through. This ensures the system remains protected even during failures.
Admin Detection
Admin status is determined by checking if the user has the settings.update
permission. This permission is typically assigned only to the "admin" role.
Token Validation
The middleware relies on softAuth middleware to validate JWT tokens. No duplicate
validation is performed, ensuring good performance.
Testing Maintenance Mode
As Admin
- Enable maintenance mode via Settings
- Verify you can still access all features
- Check activity logs for maintenance access entries
- Disable maintenance mode
As Regular User
- Have an admin enable maintenance mode
- Open the site in a different browser/incognito
- Verify you see the maintenance message
- Verify login page is accessible (for error display)
- Have admin disable maintenance mode
As Guest
- Enable maintenance mode (as admin)
- Open site in incognito (not logged in)
- Verify API requests return 503
- Verify static assets still load
Troubleshooting
Can't Disable Maintenance Mode
Cause: Admin token may have expired.
Solution:
- Log out and log back in for a fresh token
- Or update database directly (see above)
UI Broken During Maintenance
Cause: Public settings endpoint may be failing.
Solution: Verify /api/settings/public is accessible and returning valid data.
Admin Getting Blocked
Cause: User may not have settings.update permission.
Solution:
- Check user's role permissions in the database
- Ensure user is assigned the admin role
Logging
The middleware logs all maintenance-related activity:
| Log Level | Message | Description |
|---|---|---|
| INFO | [Maintenance] Admin <username> accessing... |
Admin request during maintenance |
| WARN | [Maintenance] Blocked... |
Non-admin request blocked |
| ERROR | [Maintenance] Critical error... |
Middleware failure |
Best Practices
- Notify users beforehand when possible (email, announcement)
- Keep maintenance windows short to minimize disruption
- Test critical operations before enabling maintenance
- Monitor logs during maintenance for issues
- Have database access ready in case of admin lockout
- Verify admin login works before enabling maintenance
Related Documentation
- System Settings - Where maintenance mode is configured
- Authentication - How admin access works
- Settings API - API for toggling maintenance
- Internal Maintenance Docs - Technical implementation details