feat: support reverse-proxy URL subpaths (llama-swap, SwarmUI) (#1122)

This commit is contained in:
Will Miao
2026-09-24 08:04:00 +08:00
parent 755e1a5bca
commit 2f9bd3ee7d
42 changed files with 731 additions and 103 deletions
+18
View File
@@ -0,0 +1,18 @@
"""Helpers for generating URLs that survive reverse-proxy subpath mounts."""
from __future__ import annotations
def relative_root_prefix(request_path: str) -> str:
"""Return the relative prefix ("", "../", ...) that takes a manager page
back to the mount root.
Templates reference assets and pages with relative URLs (e.g.
``{{ rel_prefix }}loras_static/...``) so the browser keeps whatever
subpath a reverse proxy (llama-swap, SwarmUI, ...) mounted ComfyUI under.
The backend only ever sees the stripped path, so the depth of the page
route is all that matters: "/loras" -> "", "/loras/recipes" -> "../".
"""
segments = [segment for segment in request_path.split("/") if segment]
return "../" * max(len(segments) - 1, 0)