Merge branch 'Hexastack:main' into fix-issue-45

This commit is contained in:
Pranav Bhat
2024-10-02 17:17:35 +05:30
committed by GitHub
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 {
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}`);
}
}
};

View File

@@ -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}`);
}
}
};