fix(caldav): Replace href with pathname from parseURL for api base

`parseURL` only return `href` for special protocols. CalDAV api base
will always be root path. Use `pathname` which will not be undefined.
This commit is contained in:
MidoriKurage 2026-03-21 23:24:16 +08:00 committed by kolaente
parent 0085772b63
commit c760a9bf72
1 changed files with 6 additions and 5 deletions

View File

@ -87,12 +87,13 @@ export const useConfigStore = defineStore('config', () => {
const migratorsEnabled = computed(() => state.availableMigrators?.length > 0)
const apiBase = computed(() => {
const {host, protocol, href} = parseURL(window.API_URL)
const {host, protocol, pathname} = parseURL(window.API_URL)
const cleanHref = href ? (href.endsWith('/')
? href.slice(0, -1)
: href) : ''
return `${protocol}//${host}${cleanHref ? `/${cleanHref}` : ''}`
// Strip the /api/v1 suffix (and optional trailing slash) to get the deployment base.
const basePath = pathname
.replace(/\/api\/v1\/?$/, '')
.replace(/\/+$/, '')
return `${protocol}//${host}${basePath}`
})
function setConfig(config: ConfigState) {