Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions ui/src/app/shared/base.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
function baseUrl(): string {
const base = document.querySelector('base');
return base ? base.getAttribute('href') : '/';
return base ? base.getAttribute('href') || '/' : '/';
}

// joinBasePath joins the <base href> value with a UI/API path while collapsing
// any duplicate slashes at the join point. This protects callers that pass
// paths with or without a leading slash from producing URLs like
// "/argo-ui//archived-workflows/..." when BASE_HREF is "/argo-ui/".
function joinBasePath(base: string, path: string): string {
const normalizedBase = (base || '/').replace(/\/+$/, '');
const normalizedPath = (path || '').replace(/^\/+/, '');
return normalizedPath ? `${normalizedBase}/${normalizedPath}` : `${normalizedBase}/`;
}

export function uiUrl(uiPath: string): string {
return baseUrl() + uiPath;
return joinBasePath(baseUrl(), uiPath);
}

export function uiUrlWithParams(uiPath: string, params: string[]): string {
if (!params) {
return uiUrl(uiPath);
}
return baseUrl() + uiPath + '?' + params.join('&');
const url = joinBasePath(baseUrl(), uiPath);
return params && params.length > 0 ? `${url}?${params.join('&')}` : url;
}

export function apiUrl(apiPath: string): string {
return `${baseUrl()}${apiPath}`;
return joinBasePath(baseUrl(), apiPath);
}

export function absoluteUrl(path: string): string {
Expand Down
Loading