From 49c35f765b45088cf7804ff74943b648d199f526 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 11:09:11 +0000 Subject: [PATCH] library: proxy URL overrides, restore Quick Add header links - OPAC_URL / STAFF_URL let Quick Add build correct links behind a reverse proxy - restore the Catalogue/Staff header links (lost when the init block was rewritten) and verify them in the browser test Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013wi3ZSot4XbUViwRFgLpRf --- library/docker-compose.yml | 2 ++ library/quickadd/app.py | 5 ++++- library/quickadd/index.html | 8 +++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/library/docker-compose.yml b/library/docker-compose.yml index c9ce8b5..cdf0424 100644 --- a/library/docker-compose.yml +++ b/library/docker-compose.yml @@ -64,6 +64,8 @@ services: KOHA_LIBRARY: ${LIBRARY_CODE:-HOME} OPAC_PORT: ${OPAC_PORT:-8080} STAFF_PORT: ${STAFF_PORT:-8081} + OPAC_URL: ${OPAC_URL:-} + STAFF_URL: ${STAFF_URL:-} QUICKADD_SOURCES: ${QUICKADD_SOURCES:-z3950:lx2.loc.gov:210/LCDB,openlibrary} ports: - "${BIND_ADDR:-0.0.0.0}:${QUICKADD_PORT:-8082}:8082" diff --git a/library/quickadd/app.py b/library/quickadd/app.py index 89c99b6..3770a0a 100644 --- a/library/quickadd/app.py +++ b/library/quickadd/app.py @@ -30,6 +30,9 @@ PASSWORD = os.environ.get("ADMIN_PASSWORD", "") LIBRARY = os.environ.get("KOHA_LIBRARY", "HOME") STAFF_PORT = os.environ.get("STAFF_PORT", "8081") OPAC_PORT = os.environ.get("OPAC_PORT", "8080") +# Set these when the site is behind a reverse proxy (different hostnames than host:port). +OPAC_URL = os.environ.get("OPAC_URL", "").rstrip("/") +STAFF_URL = os.environ.get("STAFF_URL", "").rstrip("/") DATA_DIR = os.environ.get("DATA_DIR", "/data") PORT = int(os.environ.get("PORT", "8082")) SOURCES = [s.strip() for s in os.environ.get( @@ -742,7 +745,7 @@ class Handler(BaseHTTPRequestHandler): return self._send(200, INDEX, "text/html; charset=utf-8") if path == "/api/state": return self._send(200, {"recent": load_recent()[:100], "types": get_item_types(), - "library": LIBRARY, "locations": get_locations(), "settings": load_settings(), "staff_port": STAFF_PORT, "opac_port": OPAC_PORT, + "library": LIBRARY, "locations": get_locations(), "settings": load_settings(), "staff_port": STAFF_PORT, "staff_url": STAFF_URL, "opac_url": OPAC_URL, "opac_port": OPAC_PORT, "sources": [s.split(":", 1)[0] if s.startswith("z3950") else s for s in SOURCES]}) if path == "/api/settings": return self._send(200, settings_view()) diff --git a/library/quickadd/index.html b/library/quickadd/index.html index d43b9f6..a3553bd 100644 --- a/library/quickadd/index.html +++ b/library/quickadd/index.html @@ -294,7 +294,9 @@ input.focus(); } - const printLink = (from, to) => 'http://' + location.hostname + ':' + staffPort + + let staffBase = ''; + const staffRoot = () => staffBase || ('http://' + location.hostname + ':' + staffPort); + const printLink = (from, to) => staffRoot() + '/cgi-bin/koha/labels/label-print.pl?from=' + encodeURIComponent(from) + '&to=' + encodeURIComponent(to); function rangeNote(text, from, to) { @@ -370,6 +372,10 @@ const s = await api('/api/state'); types = s.types; if (!types[type]) type = 'BOOK'; typeButtons(); staffPort = s.staff_port; settings = s.settings || {}; shelf = settings.location || ''; + staffBase = s.staff_url || ''; + $('lnk-opac').href = s.opac_url ? s.opac_url + '/' : 'http://' + location.hostname + ':' + s.opac_port + '/'; + $('lnk-staff').href = staffRoot() + '/'; + $('lnk-labels').href = staffRoot() + '/cgi-bin/koha/labels/label-edit-range.pl'; if (s.locations && s.locations.length) { const sel = $('shelf'); sel.replaceChildren(el('option', { value: '' }, '(not set / all in one place)'),