fix: handle empty BASE_URL in buildUrl to prevent Invalid URL error
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:
+2
-1
@@ -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 !== '') {
|
||||
|
||||
Reference in New Issue
Block a user