Add serve --local for using the web page on this machine
CI / test (3.10) (push) Successful in 1m24s
CI / test (3.12) (push) Successful in 1m5s
CI / test (3.13) (push) Successful in 1m3s

The page is unreachable without nginx, since every route but /healthz
needs the X-Receipt-Token header it adds. `serve --local` serves it
without a token instead: it only binds to a loopback address and answers
only requests whose Host is localhost, 127.0.0.1 or ::1, so another site
can't reach it by DNS rebinding. POSTs still need the page header.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-14 22:24:52 +00:00
co-authored by Claude Opus 5.5
parent ba92f1fbda
commit 0d4e2130a6
5 changed files with 91 additions and 14 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ CLI that prints images, notes, and QR codes to an Epson TM-T20II thermal receipt
- `receipt.py` — the CLI; subcommand per `cmd_*` function
- `receipt_tui.py` — Textual TUI (`tui` subcommand); thin layer over the `cmd_*` handlers via `receipt.run_action()`, which captures stdout/stderr for the log panel and returns an `ActionResult` (rc, output, error kind). `textual` is an optional dependency (`[tui]` extra); the CLI works without it
- `receipt_web.py` — FastAPI server (`serve` subcommand, `[web]` extra) behind the site's nginx `/receipt/` over Tailscale; requires the `X-Receipt-Token` header nginx adds, and `X-Requested-With: receipt` on POSTs. POSTs render the job in the request (`InvalidJob` → 400), queue the bytes in a `PrintQueue` and answer 202; one worker thread sends them, and the page long-polls `/api/jobs/{id}`. `/api/status` only tries the printer lock, so it never waits behind a print. Uploads print from memory. Always runs with `no_setup` (no sudo; the printer must already be reachable). Deployed on stppi, which is online over Wi-Fi and has the printer cabled to its `eth0` (printer 192.168.192.168, Pi 192.168.192.10 via the `receipt-printer` nmcli profile)
- `receipt_web.py` — FastAPI server (`serve` subcommand, `[web]` extra) behind the site's nginx `/receipt/` over Tailscale; requires the `X-Receipt-Token` header nginx adds (`serve --local` drops it, binding to loopback only and refusing non-localhost `Host`s), and `X-Requested-With: receipt` on POSTs. POSTs render the job in the request (`InvalidJob` → 400), queue the bytes in a `PrintQueue` and answer 202; one worker thread sends them, and the page long-polls `/api/jobs/{id}`. `/api/status` only tries the printer lock, so it never waits behind a print. Uploads print from memory. Always runs with `no_setup` (no sudo; the printer must already be reachable). Deployed on stppi, which is online over Wi-Fi and has the printer cabled to its `eth0` (printer 192.168.192.168, Pi 192.168.192.10 via the `receipt-printer` nmcli profile)
- Scheduling (all run inside `serve`; `[web]` extra): `receipt_store.py` (SQLite at `$RECEIPT_DATA_DIR/receipt.db`, default `~/.local/share/receipt-maker`; additive-only migrations so `update.sh` rollbacks still read it), `receipt_models.py` (pydantic specs: a schedule is trigger + blocks + options), `receipt_triggers.py` (next fire times, DST-safe, plain-English `describe()`), `receipt_sources.py` (ICS/RSS/JSON fetch + parse), `receipt_content.py` (blocks → `receipt.Block`s, `{var}` template fill — never `str.format`), `receipt_scheduler.py` (`tick(now)` is deterministic; tests drive it with a fake clock). Webhooks are `POST /hook/{id}` with a per-schedule secret
- `web/` — the page (vanilla ES modules, no build step), served by token-gated routes with relative URLs
- `deploy/` — systemd user units; `update.sh` (run by `receipt-update.timer`) tests the new Gitea commit in a scratch worktree, then fast-forwards the server's clone, restarts `receipt-web` and rolls back if `/healthz` doesn't answer. Pushing to Gitea `master` is the deploy