fix htmx refactor route mismatches and remaining TODO items

- wireguard: POST /peers with JSON encoding (was /add-peer)
- rules: delete by rule_id in URL path (was JSON body); pass rule objects with id from server; add hx-disable to initial render
- nat: port forward delete uses URL path params to match blueprint
- nat: masquerade toggle uses native hx-post/hx-vals (was inline fetch)
- app.js renderers updated to use URL path deletes for rules and forwards
- remove TODO.md
This commit is contained in:
2026-05-17 01:15:52 +00:00
parent 0e7090a2cb
commit 37039351be
26 changed files with 1737 additions and 848 deletions
+17 -1
View File
@@ -4,6 +4,8 @@ webui/api/proxy.py - Nginx proxy domain management API blueprint.
Exposed at /api/proxy/* and delegates to lib.nginx.
"""
import logging
from flask import Blueprint, jsonify, request
from lib.nginx import (
@@ -17,6 +19,7 @@ from lib.nginx import (
update_domain,
)
logger = logging.getLogger(__name__)
bp = Blueprint("proxy", __name__)
@@ -43,6 +46,7 @@ def list_domains():
try:
return _ok(get_domains())
except RuntimeError as exc:
logger.error("Failed to list proxy domains: %s", exc)
return _error(str(exc), 500)
@@ -65,8 +69,10 @@ def add_domain_bp():
add_domain(
domain, backend_host, int(backend_port), backend_proto, cert, extra_headers
)
logger.info("Proxy domain added via API: %s", domain)
return _ok({"domain": domain})
except (ValueError, RuntimeError) as exc:
logger.error("Failed to add proxy domain '%s': %s", domain, exc)
return _error(str(exc), 500)
@@ -79,6 +85,7 @@ def domain_details(domain):
return _error(f"Domain '{domain}' not found", 404)
return _ok({"domain": domain, **entry})
except RuntimeError as exc:
logger.error("Failed to get domain details: %s", exc)
return _error(str(exc), 500)
@@ -89,10 +96,12 @@ def update_domain_bp(domain):
return _error("Request body must be a JSON object with fields to update", 400)
try:
update_domain(domain, **body)
logger.info("Proxy domain '%s' updated via API", domain)
return _ok({"domain": domain})
except KeyError as exc:
return _error(str(exc), 404)
except RuntimeError as exc:
logger.error("Failed to update domain '%s': %s", domain, exc)
return _error(str(exc), 500)
@@ -103,8 +112,10 @@ def remove_domain_bp(domain):
if domain not in cfg.get("domains", {}):
return _error(f"Domain '{domain}' not found", 404)
remove_domain(domain)
logger.info("Proxy domain removed via API: %s", domain)
return _ok({"domain": domain})
except RuntimeError as exc:
logger.error("Failed to remove domain '%s': %s", domain, exc)
return _error(str(exc), 500)
@@ -117,8 +128,10 @@ def remove_domain_bp(domain):
def apply_bp():
try:
apply()
logger.info("nginx config applied via API")
return _ok(None)
except RuntimeError as exc:
logger.error("Failed to apply nginx config: %s", exc)
return _error(str(exc), 500)
@@ -128,8 +141,9 @@ def test_bp():
valid, output = test_config()
if valid:
return _ok({"valid": True, "output": output})
return jsonify({"ok": False, "error": output, "valid": False}), 400
return _error(output, 400)
except RuntimeError as exc:
logger.error("nginx config test failed: %s", exc)
return _error(str(exc), 500)
@@ -150,7 +164,9 @@ def management_bp():
auth_pass = body.get("auth_pass")
try:
set_management_proxy(domain, flask_host, int(flask_port), auth_user, auth_pass)
logger.info("Management proxy configured via API: %s", domain)
return _ok(None)
except (ValueError, RuntimeError) as exc:
code = 400 if isinstance(exc, ValueError) else 500
logger.error("Failed to set management proxy: %s", exc)
return _error(str(exc), code)