modified: app.py

modified:   config.json
This commit is contained in:
SimolZimol
2026-08-03 22:45:27 +02:00
parent cfef097f2a
commit 2a413bf7eb
2 changed files with 10 additions and 2 deletions

11
app.py
View File

@@ -44,11 +44,12 @@ app = Flask(__name__)
# neu geladen (Last-Modified-Check).
_config_mtime = 0.0
_routes = {}
_fallback = ""
def load_config(force: bool = False) -> dict:
"""Lädt die Routen-Konfiguration. Liefert dict: {path: {url, ...}}."""
global _config_mtime, _routes
global _config_mtime, _routes, _fallback
try:
mtime = os.path.getmtime(CONFIG_PATH)
except FileNotFoundError:
@@ -71,8 +72,9 @@ def load_config(force: bool = False) -> dict:
path = path if path.startswith("/") else "/" + path
normalized[path] = target
_routes = normalized
_fallback = str(data.get("fallback", "")).rstrip("/")
_config_mtime = mtime
log.info("Konfiguration geladen: %d Route(n)", len(_routes))
log.info("Konfiguration geladen: %d Route(n), Fallback=%s", len(_routes), _fallback or "-")
return _routes
@@ -289,6 +291,11 @@ def link_redirect(path: str):
if target_url is None:
target_url = routes.get(path)
# Nicht konfigurierte Pfade automatisch ans Fallback weiterleiten:
# /irgendwas -> <fallback>/irgendwas
if target_url is None and _fallback:
target_url = _fallback + "/" + path
return _handle_link(target_url)

View File

@@ -1,4 +1,5 @@
{
"fallback": "https://lubiethistoria.com",
"routes": {
"/community-mp": "https://lubiethistoria.com/community-mp",
"/": "https://lubiethistoria.com/"