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
+10
View File
@@ -83,6 +83,16 @@ sudo nmcli con add type ethernet ifname eth0 con-name receipt-printer connection
ipv4.method manual ipv4.addresses 192.168.192.10/24 ipv4.never-default yes ipv6.method disabled
```
### Running it locally
To use the page from a browser on the machine the server runs on, without nginx or a token:
```bash
./receipt.py serve --local # then open http://127.0.0.1:8765/
```
`--local` only binds to localhost (`--listen` must be `127.0.0.1`, `[::1]` or `localhost`) and refuses requests whose `Host` isn't localhost, so other sites can't reach it by DNS rebinding. It still never runs the connect script: bring the Ethernet link up first (`./receipt.py status` does), or use `./receipt.py --usb serve --local`. Schedules run here too, from the same data directory as any other `serve` on this machine; set `RECEIPT_DATA_DIR` to keep a separate one.
### Setting up the server machine
1. Clone from Gitea to `~/Coding/receipt_maker` (the path the units use), and install into a venv there: