From 008257db64c8dad85c901d32058b5bb10718f75b Mon Sep 17 00:00:00 2001 From: Amit Ranjan Date: Tue, 1 Oct 2024 19:17:54 +0530 Subject: [PATCH] feat(frontend): added fix for base url in api side --- api/src/utils/helpers/URL.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/src/utils/helpers/URL.ts b/api/src/utils/helpers/URL.ts index 5401660..df1426b 100644 --- a/api/src/utils/helpers/URL.ts +++ b/api/src/utils/helpers/URL.ts @@ -1,6 +1,10 @@ export const buildURL = (baseUrl: string, relativePath: string): string => { try { - const url = new URL(relativePath, baseUrl); + const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`; + const normalizedRelativePath = relativePath.startsWith('/') + ? relativePath.slice(1) + : relativePath; + const url = new URL(normalizedRelativePath, normalizedBaseUrl); return url.toString(); } catch {