feat(hosting): add maintenance mode middleware + sm down/up (closes #160)#196
Open
antosubash wants to merge 1 commit into
Open
feat(hosting): add maintenance mode middleware + sm down/up (closes #160)#196antosubash wants to merge 1 commit into
antosubash wants to merge 1 commit into
Conversation
) Sentinel-file maintenance mode that short-circuits requests with HTTP 503 when active, exempts /health/live and /health/ready, returns JSON for Inertia XHR and the static maintenance.html for browser requests, and supports a ?sm_bypass=<secret> query-string handshake that issues an HttpOnly cookie. CLI: sm down --secret X --message "..." --retry 60 [--until ISO]; sm down --status; sm up. Writes/reads App_Data/maintenance.json under the host project. A FileSystemWatcher in the running app picks up changes without restart. Acceptance for #160: - Middleware after auth, before rate limiting / module middleware - Health probes exempted - Inertia request returns JSON 503 with component "System/Maintenance" - Bypass cookie HttpOnly, Secure (https or non-dev), SameSite=Lax - CLI commands wired with examples - 9 middleware tests + 5 sentinel tests, all green Deferred to follow-ups: per-tenant maintenance mode, docs site page, and the System/Maintenance React page (the static HTML fallback is enough for the SPA shell today).
Deploying simplemodule-website with
|
| Latest commit: |
22789ec
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://26ba8437.simplemodule-website.pages.dev |
| Branch Preview URL: | https://claude-fix-missing-issues-0q.simplemodule-website.pages.dev |
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
Closes #160.
Sentinel-file maintenance mode (Laravel's
php artisan downequivalent):MaintenanceModeMiddlewareshort-circuits requests with HTTP 503 when active, setsRetry-After, exempts/health/live+/health/ready, returns JSON 503 for Inertia/JSON requests (component: "System/Maintenance") and the staticmaintenance.htmlfor browsers.?sm_bypass=<secret>exchanges the secret (constant-time compared) for an HttpOnly, SameSite=Lax, Secure (https or non-dev) cookie, then 302s back to the original URL with the secret stripped.FileMaintenanceModeStoreis sentinel-backed (App_Data/maintenance.json) with aFileSystemWatcherso the running app picks up CLI writes without restart —GetState()is a hot-path field read, no disk I/O per request.sm down --secret X --message "..." --retry 60 [--until <ISO8601>](auto-generates a secret if--secretis omitted and prints the bypass URL),sm down --status,sm up.Pipeline placement
After auth so the bypass cookie is set under a known identity; before rate limiting / module middleware so we don't spend budget on requests we're going to 503.
Acceptance criteria from #160
/health/live,/health/ready) exemptedThe React
System/MaintenanceInertia page is also deferred — the static HTML fallback is sufficient for browser requests today, and Inertia clients receive the JSON payload so an SPA can render the page in a follow-up without a server change.Test plan
dotnet test tests/SimpleModule.Core.Tests --filter MaintenanceModeMiddlewareTests→ 9/9 pass (passthrough, 503 + Retry-After, both health paths exempt, Inertia JSON 503, bypass query → cookie + redirect, wrong secret still 503s, valid cookie passes, expiredUntilpasses)dotnet run --project tests/SimpleModule.Cli.Tests -- -class SimpleModule.Cli.Tests.MaintenanceSentinelTests→ 5/5 pass (hash determinism, hash uniqueness, JSON round-trip, absent + corrupt file handling)dotnet test tests/SimpleModule.Core.Tests→ 206/206 passdotnet build SimpleModule.slnx→ clean, 0 warningsdotnet csharpier checkon touched files → cleandotnet run --project template/SimpleModule.Host+sm down --secret hellofrom another shell → verify 503 withRetry-After, then?sm_bypass=hellolets the session throughGenerated by Claude Code