mirror of
https://github.com/luxfi/kms.git
synced 2026-07-27 05:54:18 +00:00
Removing the embedded console stopped the SPA answering every unmatched path, but the mux could still emit HTML on its own: http.ServeMux writes an HTML body for the implicit trailing-slash redirect, http.Error writes text/plain, and the default unmatched-route handler writes "404 page not found". jsonOnly wraps the mux so every response carries application/json and a JSON body regardless of what the handler underneath wrote. Status and Location are untouched, so redirects still redirect — they just stop explaining themselves in HTML. "/" is registered as a JSON 404 carrying the requested path, so a wrong URL says so in a form a caller can act on. This is the failure that let genesis call /api/v3/secrets/raw against this host and read the console page back instead of an error. Four tests pin it: unmatched paths are JSON 404s, redirect bodies contain no HTML but keep Location, plain text errors become JSON with the message preserved, and JSON handlers pass through byte for byte. Co-authored-by: Hanzo Dev <dev@hanzo.ai>