diff --git a/app.py b/app.py index f092e5d..b1f6375 100644 --- a/app.py +++ b/app.py @@ -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 -> /irgendwas + if target_url is None and _fallback: + target_url = _fallback + "/" + path + return _handle_link(target_url) diff --git a/config.json b/config.json index ae3490c..61d7f3f 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,5 @@ { + "fallback": "https://lubiethistoria.com", "routes": { "/community-mp": "https://lubiethistoria.com/community-mp", "/": "https://lubiethistoria.com/"