diff --git a/api/src/utils/helpers/URL.ts b/api/src/utils/helpers/URL.ts index 5401660..6f08386 100644 --- a/api/src/utils/helpers/URL.ts +++ b/api/src/utils/helpers/URL.ts @@ -1,9 +1,14 @@ export const buildURL = (baseUrl: string, relativePath: string): string => { try { - const url = new URL(relativePath, baseUrl); - - return url.toString(); + return new URL(relativePath).toString(); } catch { - throw new Error(`Invalid base URL: ${baseUrl}`); + try { + return new URL( + relativePath.replace(/^\//, ''), + baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`, + ).toString(); + } catch { + throw new Error(`Invalid base URL: ${baseUrl}`); + } } }; diff --git a/frontend/src/utils/URL.ts b/frontend/src/utils/URL.ts index b662c9e..dc1c20d 100644 --- a/frontend/src/utils/URL.ts +++ b/frontend/src/utils/URL.ts @@ -28,11 +28,16 @@ export const getFromQuery = ({ export const buildURL = (baseUrl: string, relativePath: string): string => { try { - const url = new URL(relativePath, baseUrl); - - return url.toString(); + return new URL(relativePath).toString(); } catch { - throw new Error(`Invalid base URL: ${baseUrl}`); + try { + return new URL( + relativePath.replace(/^\//, ""), + baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`, + ).toString(); + } catch { + throw new Error(`Invalid base URL: ${baseUrl}`); + } } };