mirror of
https://github.com/hexastack/hexabot
synced 2025-05-05 21:34:41 +00:00
feat(fix): added fix for the relative url too
This commit is contained in:
parent
008257db64
commit
3a7b0ab4fb
@ -1,13 +1,14 @@
|
|||||||
export const buildURL = (baseUrl: string, relativePath: string): string => {
|
export const buildURL = (baseUrl: string, relativePath: string): string => {
|
||||||
try {
|
try {
|
||||||
const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
|
return new URL(relativePath).toString();
|
||||||
const normalizedRelativePath = relativePath.startsWith('/')
|
|
||||||
? relativePath.slice(1)
|
|
||||||
: relativePath;
|
|
||||||
const url = new URL(normalizedRelativePath, normalizedBaseUrl);
|
|
||||||
|
|
||||||
return url.toString();
|
|
||||||
} catch {
|
} 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}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -28,15 +28,16 @@ export const getFromQuery = ({
|
|||||||
|
|
||||||
export const buildURL = (baseUrl: string, relativePath: string): string => {
|
export const buildURL = (baseUrl: string, relativePath: string): string => {
|
||||||
try {
|
try {
|
||||||
const normalizedBaseUrl = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
return new URL(relativePath).toString();
|
||||||
const normalizedRelativePath = relativePath.startsWith("/")
|
|
||||||
? relativePath.slice(1)
|
|
||||||
: relativePath;
|
|
||||||
const url = new URL(normalizedRelativePath, normalizedBaseUrl);
|
|
||||||
|
|
||||||
return url.toString();
|
|
||||||
} catch {
|
} 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}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user