mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-05 02:29:59 +01:00
* fix(middleware): a rewrite behind Caddy dialled TLS at an http socket
Production 500'd for every signed-in visitor on the locale root. Signed-out
visitors were fine, which is why it shipped.
Failed to proxy https://localhost:4025/de/portal
EPROTO ... tls_validate_record_header: wrong version number
`request.nextUrl.clone()` inherits the EXTERNAL protocol behind the reverse
proxy, so the cloned URL reads `https://localhost:4025/...` while the app
itself listens on plain http at that port. Next does not recognise that origin
as its own, treats the rewrite as an external proxy target, and opens a TLS
connection to an http socket.
Nothing in the test suite could have caught it, and that is the part worth
recording rather than the one-line cause. The DECISION was extracted into a
pure, tested function precisely so it could be covered — and it was, including
the self-rewrite loop — but the decision was never wrong. The MECHANISM was,
and the mechanism only misbehaves with a real reverse proxy in front of it.
Neither CI nor `pnpm start` has one, and the branch only ran when a session
cookie was present, so a production build exercised in a browser was green too.
The rewrite goes. "Show a different page at the same address" is still the
right idea — it is a decision for the PAGE to make, where no URL is
reconstructed and no protocol is guessed. `lib/i18n/landing.ts` goes with it
rather than sitting unwired, which is the same defect as a health check nobody
calls.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FzYBD3sZroCAYeRgTYrpfT
* test(deploy): smoke the live site, signed in and signed out
A green deploy is not a working site, and this outage proved it in the most
expensive way available: 339 tests, lint, typecheck and a production build
exercised in a browser, all green, while the locale root returned 500 to every
signed-in visitor.
The thing that would have caught it takes one second:
curl -H "Cookie: __Secure-authjs.session-token=x" /de → 500
A cookie being PRESENT is enough. That is the whole trick, because the code
paths this class of bug lives in — routing, rewrites, redirects — branch on
the cookie long before anyone validates it.
So `scripts/smoke.sh` requests every page a visitor can reach by name, twice,
once each way round, and runs as a job after the deploy. A release that cannot
serve its own home page now turns the Deploy run red instead of waiting to be
noticed.
What the cookie does NOT prove, stated in the script so nobody mistakes it for
more than it is: it is not a real session. `auth()` rejects it and the page
renders signed-out. It exercises "is a session cookie present", not "is this
person authenticated". A genuinely authenticated end-to-end test needs a test
account and a real login flow, and is worth doing separately.
Also checks that `/` stays a 307 and not a 308 — caching the locale
negotiation as permanent would pin every later visitor to whoever asked first —
and reads `/api/health`'s schema verdict rather than its status code, since a
deploy that cannot use its own tables still answers 200 by design.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FzYBD3sZroCAYeRgTYrpfT
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>