Repository navigation
Add maintenance mode middleware (#342) - #343
Merged
Merged
Conversation
Toggle via MAINTENANCE_MODE env var: off | read-only | full.
read-only blocks mutations except /admin/* and /webhooks/*; full blocks
everything except /health, /notices, and /. Response is 503 with
Retry-After header and {error, mode, eta} body.
CLI detects the 503 maintenance payload, raises MaintenanceError, and
prints a bordered banner instead of a stack trace.
Needed for the SCCN Cloudflare migration (Epic #314) to freeze the
personal-account backend during the D1 dump/restore window.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR343Version: 🤖 Updated on each push. |
Code review findings fixed in this commit: - Extract MaintenanceMode to backend/src/types/maintenance.ts so the literal union is defined in one place (was duplicated across 3 files plus 2 runtime guards); drift risk removed - Whitelist POST /auth/login in read-only so admins whose tokens expire can re-authenticate to hit /admin/*; signup stays blocked - parseMode now logs a console.error once per isolate on unknown MAINTENANCE_MODE values instead of silently falling back to off; a typo like 'readonly' would otherwise leave prod unprotected - respond503 logs blocked requests so Cloudflare logs confirm why 503s are being returned during a freeze - Mark MaintenanceError.mode and .eta readonly; validate eta with typeof instead of 'as string | null' cast - Print maintenance banner from request() itself (once per process via module-scoped flag) so per-command catches that swallow errors still surface the banner; drops the duplicated banner helper in src/index.ts - Use errorDetail() in top-level catch instead of err.message || err - Trim epic/issue references from middleware JSDoc and wrangler.toml comment Test coverage added: - PATCH/PUT/DELETE/OPTIONS in read-only - Path-prefix edge cases: /adminfoo, /admin (no slash) both 503 - /auth/login passes in read-only, /auth/signup blocks - /healthz and /notices/123 confirm exact-match whitelist - Retry-After asserted in full mode - Invalid MAINTENANCE_MODE string actually exercises parseMode fallback - New test/maintenance-client.test.ts covers CLI-side MaintenanceError detection against a real local Bun.serve: read-only/full/unknown mode, missing body, non-string eta coercion, default message
Contributor
Author
Review fixes applied (f4e7799)Addressed the findings from all 5 review agents. Test count: 26 backend + 7 CLI = 33 passing. Critical
Important
Improvements
Not changed (false-positive or nice-to-have deferred)
|
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
maintenanceModemiddleware with three modes (off|read-only|full) toggled via theMAINTENANCE_MODEenv var inwrangler.toml; redeploy to flipread-onlyblocksPOST/PUT/DELETE/PATCHeverywhere except/admin/*and/webhooks/*;fullblocks everything except/health,/notices, and/Retry-After: 3600header plus JSON{error, message, mode, eta}MaintenanceErrorsubclass ofApiError, and prints a bordered banner instead of a stack traceWhy
Blocks Epic #314 Phase 6 (D1 data migration) and Phase 8 (DNS cutover). Needed so we can freeze writes on the personal-account backend during the dump/restore window without losing in-flight writes.
Test plan
bun test backend/test/maintenance.test.ts(15 pass)tsc --noEmiton bothbackend/and rootbun run deploy:dev) and smoke-test 503 withcurl -X POSTMAINTENANCE_MODE = "off"until the migration windowCloses #342.