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).
|
# neu geladen (Last-Modified-Check).
|
||||||
_config_mtime = 0.0
|
_config_mtime = 0.0
|
||||||
_routes = {}
|
_routes = {}
|
||||||
|
_fallback = ""
|
||||||
|
|
||||||
|
|
||||||
def load_config(force: bool = False) -> dict:
|
def load_config(force: bool = False) -> dict:
|
||||||
"""Lädt die Routen-Konfiguration. Liefert dict: {path: {url, ...}}."""
|
"""Lädt die Routen-Konfiguration. Liefert dict: {path: {url, ...}}."""
|
||||||
global _config_mtime, _routes
|
global _config_mtime, _routes, _fallback
|
||||||
try:
|
try:
|
||||||
mtime = os.path.getmtime(CONFIG_PATH)
|
mtime = os.path.getmtime(CONFIG_PATH)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@@ -71,8 +72,9 @@ def load_config(force: bool = False) -> dict:
|
|||||||
path = path if path.startswith("/") else "/" + path
|
path = path if path.startswith("/") else "/" + path
|
||||||
normalized[path] = target
|
normalized[path] = target
|
||||||
_routes = normalized
|
_routes = normalized
|
||||||
|
_fallback = str(data.get("fallback", "")).rstrip("/")
|
||||||
_config_mtime = mtime
|
_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
|
return _routes
|
||||||
|
|
||||||
|
|
||||||
@@ -289,6 +291,11 @@ def link_redirect(path: str):
|
|||||||
if target_url is None:
|
if target_url is None:
|
||||||
target_url = routes.get(path)
|
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)
|
return _handle_link(target_url)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"fallback": "https://lubiethistoria.com",
|
||||||
"routes": {
|
"routes": {
|
||||||
"/community-mp": "https://lubiethistoria.com/community-mp",
|
"/community-mp": "https://lubiethistoria.com/community-mp",
|
||||||
"/": "https://lubiethistoria.com/"
|
"/": "https://lubiethistoria.com/"
|
||||||
|
|||||||
Reference in New Issue
Block a user