Add /receipt/, an admin-gated proxy to the receipt printer on stppi
The receipt_maker repo's `receipt serve` runs on stppi, which reaches the Epson printer over the home LAN, and serves a page for printing a note or an uploaded image. nginx gates /receipt/ on the admin session like /tracker/, strips the prefix, adds the shared X-Receipt-Token and proxies over Tailscale to RECEIPT_WEB_UPSTREAM (the one upstream off this host). When stppi is unreachable, @receipt_offline answers 503 instead of a bare 502. Both variables are defaulted in entrypoint.sh, and the token is quoted in the template, so an unset pair still renders a valid config (/receipt/ then reads "offline"). The admin panel links to the page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+8
-1
@@ -87,6 +87,11 @@
|
||||
# SILVERBULLET_PUBLIC_HOST / _PORT
|
||||
# public notes viewer upstream (defaulted below)
|
||||
# PYTHON_HOST / PYTHON_PORT FastAPI upstream (defaulted below)
|
||||
# RECEIPT_WEB_UPSTREAM host:port of the receipt printer server on
|
||||
# stppi, over Tailscale (defaulted below to
|
||||
# a dead port, so /receipt/ reads "offline")
|
||||
# RECEIPT_WEB_TOKEN shared secret nginx adds to /receipt/
|
||||
# requests (defaulted below to empty)
|
||||
# DEV_MODE "true" only via docker-compose.dev.yml
|
||||
# CERT_WATCH_INTERVAL optional, seconds between certificate-watch
|
||||
# polls (default 60). Production only.
|
||||
@@ -107,11 +112,13 @@ export SILVERBULLET_HOST="${SILVERBULLET_HOST:-silverbullet}"
|
||||
export SILVERBULLET_PORT="${SILVERBULLET_PORT:-3000}"
|
||||
export SILVERBULLET_PUBLIC_HOST="${SILVERBULLET_PUBLIC_HOST:-silverbullet-public}"
|
||||
export SILVERBULLET_PUBLIC_PORT="${SILVERBULLET_PUBLIC_PORT:-3000}"
|
||||
export RECEIPT_WEB_UPSTREAM="${RECEIPT_WEB_UPSTREAM:-127.0.0.1:9}"
|
||||
export RECEIPT_WEB_TOKEN="${RECEIPT_WEB_TOKEN:-}"
|
||||
|
||||
# The envsubst allow-list, defined once and reused by both full-config branches
|
||||
# and by every partial, so the lists cannot drift apart. It MUST stay
|
||||
# single-quoted here and be passed as "$ENVSUBST_VARS" (one argument) below.
|
||||
ENVSUBST_VARS='${DOMAIN} ${BACKEND_HOST} ${BACKEND_PORT} ${BACKEND_ENDPOINT} ${ICECAST_HOST} ${ICECAST_PORT} ${GITEA_HOST} ${GITEA_PORT} ${SILVERBULLET_HOST} ${SILVERBULLET_PORT} ${SILVERBULLET_PUBLIC_HOST} ${SILVERBULLET_PUBLIC_PORT} ${PYTHON_HOST} ${PYTHON_PORT}'
|
||||
ENVSUBST_VARS='${DOMAIN} ${BACKEND_HOST} ${BACKEND_PORT} ${BACKEND_ENDPOINT} ${ICECAST_HOST} ${ICECAST_PORT} ${GITEA_HOST} ${GITEA_PORT} ${SILVERBULLET_HOST} ${SILVERBULLET_PORT} ${SILVERBULLET_PUBLIC_HOST} ${SILVERBULLET_PUBLIC_PORT} ${PYTHON_HOST} ${PYTHON_PORT} ${RECEIPT_WEB_UPSTREAM} ${RECEIPT_WEB_TOKEN}'
|
||||
|
||||
# Render the shared proxy route table. Done ONCE, here, ahead of the three-way
|
||||
# decision, rather than inside each branch:
|
||||
|
||||
@@ -88,6 +88,11 @@
|
||||
# nginx_dev_common.conf.template) and the garage-webui admin UI.
|
||||
set $upstream_garage_web http://garage:3902;
|
||||
set $upstream_garage_webui http://garage-webui:3909;
|
||||
# The receipt printer's server is the one upstream OFF this host: it
|
||||
# runs on stppi, which reaches the printer over the home LAN, and is
|
||||
# reached over Tailscale by IP (MagicDNS names don't resolve in this
|
||||
# container).
|
||||
set $upstream_receipt "http://${RECEIPT_WEB_UPSTREAM}";
|
||||
|
||||
# ---- Backend API -----------------------------------------------------
|
||||
# Two patterns repeat through every proxied location below:
|
||||
@@ -538,6 +543,45 @@
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# ---- Receipt printer (/receipt/) ----
|
||||
# The adamf/receipt_maker repo's `receipt serve`, running on stppi
|
||||
# (not in this stack: that machine reaches the printer on the home LAN). A page
|
||||
# for printing a note or an uploaded image, plus its API. Gated like
|
||||
# /tracker/ on the admin session; the prefix IS stripped. The server
|
||||
# trusts nothing without X-Receipt-Token, which only this proxy adds
|
||||
# (proxy_set_header replaces any copy the client sent). The value is
|
||||
# quoted so an unset token still renders a valid config. When stppi
|
||||
# is off or unreachable the connect fails fast and @receipt_offline answers.
|
||||
location = /receipt {
|
||||
return 301 /receipt/;
|
||||
}
|
||||
|
||||
location ^~ /receipt/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
error_page 502 504 = @receipt_offline;
|
||||
limit_req zone=api burst=10 nodelay;
|
||||
# The server caps uploads at 16 MB; this leaves room for the
|
||||
# multipart framing around one.
|
||||
client_max_body_size 17m;
|
||||
rewrite ^/receipt/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_receipt;
|
||||
proxy_connect_timeout 3s;
|
||||
# An image print (connect, dither, send) takes a few seconds; a
|
||||
# dead printer socket gives up after escpos's 60 s timeout.
|
||||
proxy_read_timeout 90s;
|
||||
proxy_set_header X-Receipt-Token "${RECEIPT_WEB_TOKEN}";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location @receipt_offline {
|
||||
default_type text/plain;
|
||||
return 503 "The receipt printer machine is offline.\n";
|
||||
}
|
||||
|
||||
# Where the tracker used to be. The SPA routes were client-side, so
|
||||
# these only catch bookmarks and typed URLs. The userscript's old
|
||||
# @updateURL lands on the third, which is how installed copies find
|
||||
@@ -552,7 +596,7 @@
|
||||
return 301 /jobs/job-capture.user.js;
|
||||
}
|
||||
|
||||
# ---- Admin gate (/sb/, /jobs/, /tracker/, /dozzle/, /garage/, /radio/admin/, /uploads/private/) ----
|
||||
# ---- Admin gate (/sb/, /jobs/, /tracker/, /receipt/, /dozzle/, /garage/, /radio/admin/, /uploads/private/) ----
|
||||
# (/uploads/private/ is declared in the including template, not here;
|
||||
# it points at the two locations below by name.)
|
||||
# `auth_request` makes nginx fire a subrequest here before serving the
|
||||
|
||||
Reference in New Issue
Block a user