feat(frontend): added fix for the base url
This commit is contained in:
Mohamed Marrouchi 2024-10-02 07:13:54 +01:00 committed by GitHub
commit 28313e1cf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 8 deletions

View File

@ -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 {
try {
return new URL(
relativePath.replace(/^\//, ''),
baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`,
).toString();
} catch {
throw new Error(`Invalid base URL: ${baseUrl}`);
}
}
};

View File

@ -28,12 +28,17 @@ 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 {
try {
return new URL(
relativePath.replace(/^\//, ""),
baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`,
).toString();
} catch {
throw new Error(`Invalid base URL: ${baseUrl}`);
}
}
};
export const isAbsoluteUrl = (value: string = ""): boolean => {