fix: handle empty BASE_URL in buildUrl to prevent Invalid URL error
CI / Typecheck, test & build (push) Successful in 2m22s
CI / Deploy to Cloudflare Workers (push) Failing after 1m6s

When VITE_API_BASE_URL is unset, BASE_URL defaults to '', which causes
new URL(path, '') to throw TypeError: Invalid URL. Fall back to
location.origin (browser/jsdom) or 'http://localhost' (SSR).
This commit is contained in:
2026-08-31 00:36:52 +08:00
parent 78c28ed1bd
commit 41a6391ce6
+2 -1
View File
@@ -28,7 +28,8 @@ interface RequestOptions {
}
function buildUrl(path: string, params?: ListParams): string {
const url = new URL(path, BASE_URL)
const base = BASE_URL || (typeof location !== 'undefined' ? location.origin : 'http://localhost')
const url = new URL(path, base)
if (params) {
for (const [key, value] of Object.entries(params)) {
if (value !== undefined && value !== null && value !== '') {