PUBLIC_URL: Kalender-Link per Umgebungsvariable (HTTPS hinter Proxy)
This commit is contained in:
@@ -82,6 +82,7 @@ Die eigentliche iCal-Datei für Abos und direkten Download ist unter `/calendar.
|
|||||||
|
|
||||||
- `KANTINE_BASE_URL` – Basis-URL der Kantine (Standard: `http://kantine-bhz.de`)
|
- `KANTINE_BASE_URL` – Basis-URL der Kantine (Standard: `http://kantine-bhz.de`)
|
||||||
- `REFRESH_INTERVAL_SECONDS` – Sekunden zwischen Aktualisierungen (Standard: 86400 = 24 h)
|
- `REFRESH_INTERVAL_SECONDS` – Sekunden zwischen Aktualisierungen (Standard: 86400 = 24 h)
|
||||||
|
- `PUBLIC_URL` – Öffentliche Basis-URL (z. B. `https://kantine.elpatron.me`). Wenn gesetzt, wird diese URL für die Kalender-Abo-URL auf der Startseite verwendet. **Empfohlen hinter HTTPS-Proxy**, falls der Proxy keine `X-Forwarded-Proto`/`X-Forwarded-Host`-Header sendet – sonst erscheint dort weiterhin `http://`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -92,11 +93,12 @@ Für den Betrieb als Container (z. B. auf einem Server):
|
|||||||
**Build und Run:**
|
**Build und Run:**
|
||||||
```bash
|
```bash
|
||||||
docker build -t kantine2ical .
|
docker build -t kantine2ical .
|
||||||
docker run -p 8000:8000 kantine2ical
|
docker run -p 8000:8000 -e PUBLIC_URL=https://kantine.elpatron.me kantine2ical
|
||||||
```
|
```
|
||||||
|
(Ersetzen Sie `https://kantine.elpatron.me` durch Ihre öffentliche HTTPS-URL. Dann zeigt die Startseite die Kalender-URL mit `https://`.)
|
||||||
|
|
||||||
- **Startseite** (Anleitung + Abo-URL): `http://<host>:8000/`
|
- **Startseite** (Anleitung + Abo-URL): `http://<host>:8000/` bzw. Ihre HTTPS-URL
|
||||||
- **iCal-Abo:** `http://<host>:8000/calendar.ics`
|
- **iCal-Abo:** `http://<host>:8000/calendar.ics` bzw. `https://<host>/calendar.ics`
|
||||||
|
|
||||||
**Mit Docker Compose:**
|
**Mit Docker Compose:**
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
4
app.py
4
app.py
@@ -19,6 +19,8 @@ from kantine2ical import BASE_URL, empty_ical_bytes, refresh_speiseplan
|
|||||||
# Konfiguration (Umgebungsvariablen mit Fallback)
|
# Konfiguration (Umgebungsvariablen mit Fallback)
|
||||||
KANTINE_BASE_URL = os.environ.get("KANTINE_BASE_URL", BASE_URL)
|
KANTINE_BASE_URL = os.environ.get("KANTINE_BASE_URL", BASE_URL)
|
||||||
REFRESH_INTERVAL_SECONDS = int(os.environ.get("REFRESH_INTERVAL_SECONDS", "86400")) # 24h
|
REFRESH_INTERVAL_SECONDS = int(os.environ.get("REFRESH_INTERVAL_SECONDS", "86400")) # 24h
|
||||||
|
# Öffentliche Basis-URL (z. B. https://kantine.elpatron.me), wenn Proxy keine X-Forwarded-* sendet
|
||||||
|
PUBLIC_URL = os.environ.get("PUBLIC_URL", "").strip().rstrip("/")
|
||||||
|
|
||||||
# Template-Ordner immer relativ zu dieser Datei (funktioniert mit Gunicorn/Docker)
|
# Template-Ordner immer relativ zu dieser Datei (funktioniert mit Gunicorn/Docker)
|
||||||
_template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")
|
_template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")
|
||||||
@@ -90,7 +92,7 @@ def _format_last_refresh() -> str | None:
|
|||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
"""Startseite mit Anleitung zur iCal-Einbettung (Google und andere)."""
|
"""Startseite mit Anleitung zur iCal-Einbettung (Google und andere)."""
|
||||||
base = request.url_root.rstrip("/")
|
base = PUBLIC_URL or request.url_root.rstrip("/")
|
||||||
calendar_url = f"{base}/calendar.ics"
|
calendar_url = f"{base}/calendar.ics"
|
||||||
last_refresh_str = _format_last_refresh()
|
last_refresh_str = _format_last_refresh()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -4,3 +4,6 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
# Öffentliche HTTPS-URL, damit die Startseite den Kalender-Link mit https anzeigt
|
||||||
|
- PUBLIC_URL=https://kantine.elpatron.me
|
||||||
|
|||||||
Reference in New Issue
Block a user