Skip to content

Commit 1e066ee

Browse files
fix: subpath routing for reverse proxy, embedded frontends, nginx/apache subpath hosting, etc. (like SwarmUI) (#7115)
Fixes #6995 -- restores subpath routing for subpath deployments (e.g., SwarmUI, nginx/apache subpaths, etc.). Fix only applies to non-cloud, non-Electron deployments As pointed out [here](693fbbd#r171491977), [693fbbd](693fbbd) changed router base path logic from `window.location.pathname` to `import.meta.env.BASE_URL`. Combined with [6c9743c](6c9743c) setting `base: ''` for non-cloud builds, the router defaults to `/` and ignores actual subpaths. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7115-fix-subpath-routing-for-reverse-proxy-embedded-frontends-nginx-apache-subpath-hosting--2be6d73d365081188ec8d360c1cd88f7) by [Unito](https://www.unito.io)
1 parent 5c330fd commit 1e066ee

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/router.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ import { cloudOnboardingRoutes } from './platform/cloud/onboarding/onboardingClo
2020

2121
const isFileProtocol = window.location.protocol === 'file:'
2222

23-
// Determine base path for the router
24-
// - Electron: always root
25-
// - Web: rely on Vite's BASE_URL (configured via vite.config `base`)
23+
/**
24+
* Determine base path for the router.
25+
* - Electron: always root
26+
* - Cloud: use Vite's BASE_URL (configured at build time)
27+
* - Standard web (including reverse proxy subpaths): use window.location.pathname
28+
* to support deployments like http://mysite.com/ComfyUI/
29+
*/
2630
function getBasePath(): string {
2731
if (isElectron()) return '/'
28-
// Vite injects BASE_URL at build/dev time; default to '/'
29-
return import.meta.env?.BASE_URL || '/'
32+
if (isCloud) return import.meta.env?.BASE_URL || '/'
33+
return window.location.pathname
3034
}
3135

3236
const basePath = getBasePath()

0 commit comments

Comments
 (0)