From 2871fb432c9f90f8c76220d6d58e6a95a2c8fc08 Mon Sep 17 00:00:00 2001 From: Amit Ranjan Date: Mon, 30 Sep 2024 22:04:57 +0530 Subject: [PATCH 1/3] feat(frontend): added fix for the base url --- frontend/src/utils/URL.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/utils/URL.ts b/frontend/src/utils/URL.ts index b662c9e..b38c124 100644 --- a/frontend/src/utils/URL.ts +++ b/frontend/src/utils/URL.ts @@ -28,7 +28,11 @@ export const getFromQuery = ({ 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 { From 008257db64c8dad85c901d32058b5bb10718f75b Mon Sep 17 00:00:00 2001 From: Amit Ranjan Date: Tue, 1 Oct 2024 19:17:54 +0530 Subject: [PATCH 2/3] 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 { From 3a7b0ab4fb5cbabb5a05d18db880c82f68c628c7 Mon Sep 17 00:00:00 2001 From: Amit Ranjan Date: Tue, 1 Oct 2024 20:05:07 +0530 Subject: [PATCH 3/3] feat(fix): added fix for the relative url too --- api/src/utils/helpers/URL.ts | 17 +++++++++-------- frontend/src/utils/URL.ts | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/api/src/utils/helpers/URL.ts b/api/src/utils/helpers/URL.ts index df1426b..6f08386 100644 --- a/api/src/utils/helpers/URL.ts +++ b/api/src/utils/helpers/URL.ts @@ -1,13 +1,14 @@ export const buildURL = (baseUrl: string, relativePath: string): string => { try { - const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`; - const normalizedRelativePath = relativePath.startsWith('/') - ? relativePath.slice(1) - : relativePath; - const url = new URL(normalizedRelativePath, normalizedBaseUrl); - - 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 b38c124..dc1c20d 100644 --- a/frontend/src/utils/URL.ts +++ b/frontend/src/utils/URL.ts @@ -28,15 +28,16 @@ export const getFromQuery = ({ export const buildURL = (baseUrl: string, relativePath: string): string => { try { - const normalizedBaseUrl = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`; - const normalizedRelativePath = relativePath.startsWith("/") - ? relativePath.slice(1) - : relativePath; - const url = new URL(normalizedRelativePath, normalizedBaseUrl); - - 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}`); + } } };