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
+19
View File
@@ -0,0 +1,19 @@
/**
* Base-path helpers for code running inside the ComfyUI page.
*
* When ComfyUI is served under a URL subpath by a reverse proxy (e.g.
* llama-swap serves it at "/comfyui/", SwarmUI at "/ComfyBackendDirect/"),
* the ComfyUI SPA always sits at the root of that prefix, so the prefix is
* the current pathname without the trailing slash — the same convention the
* ComfyUI frontend uses for its own api_base. Proxies strip the prefix and
* forward no headers, so the page URL is the only place to learn it.
*/
export function getComfyUIBasePath() {
const { pathname } = window.location;
return pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
}
export function lmUrl(path) {
return `${getComfyUIBasePath()}${path}`;
}