mirror of
https://github.com/hexastack/hexabot
synced 2024-11-24 04:53: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 => {
|
||||
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 {
|
||||
try {
|
||||
return new URL(
|
||||
relativePath.replace(/^\//, ''),
|
||||
baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`,
|
||||
).toString();
|
||||
} catch {
|
||||
throw new Error(`Invalid base URL: ${baseUrl}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -28,16 +28,17 @@ 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 {
|
||||
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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user