modified: app.py
modified: config.json
This commit is contained in:
11
app.py
11
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 -> <fallback>/irgendwas
|
||||
if target_url is None and _fallback:
|
||||
target_url = _fallback + "/" + path
|
||||
|
||||
return _handle_link(target_url)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user