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
+46
View File
@@ -0,0 +1,46 @@
import { afterEach, describe, expect, it } from 'vitest'
import { getLmBasePath, lmApiUrl } from '@/utils/basePath'
const originalPathname = window.location.pathname
function setPathname(pathname: string) {
window.history.replaceState(null, '', pathname)
}
afterEach(() => {
setPathname(originalPathname)
})
describe('getLmBasePath', () => {
it('returns an empty string when ComfyUI is served at the root', () => {
setPathname('/')
expect(getLmBasePath()).toBe('')
})
it('strips the trailing slash from a subpath prefix', () => {
setPathname('/comfyui/')
expect(getLmBasePath()).toBe('/comfyui')
})
it('keeps a prefix without a trailing slash as-is', () => {
setPathname('/ComfyBackendDirect')
expect(getLmBasePath()).toBe('/ComfyBackendDirect')
})
})
describe('lmApiUrl', () => {
it('leaves root-absolute paths unchanged at the root', () => {
setPathname('/')
expect(lmApiUrl('/api/lm/loras/list')).toBe('/api/lm/loras/list')
})
it('prepends the subpath prefix to root-absolute paths', () => {
setPathname('/comfyui/')
expect(lmApiUrl('/api/lm/loras/list')).toBe('/comfyui/api/lm/loras/list')
})
})