2022-08-22 15:09:41 +00:00
|
|
|
import ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
|
|
|
|
import { joinPath } from "./joinPath";
|
|
|
|
|
|
|
|
export const convertClientToUrl = (
|
|
|
|
{ rootUrl, baseUrl }: ClientRepresentation,
|
2023-07-11 14:03:21 +00:00
|
|
|
adminClientBaseUrl: string,
|
2022-08-22 15:09:41 +00:00
|
|
|
) => {
|
|
|
|
// absolute base url configured, use base url is
|
|
|
|
if (baseUrl?.startsWith("http")) {
|
|
|
|
return baseUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
(rootUrl === "${authBaseUrl}" || rootUrl === "${authAdminUrl}") &&
|
|
|
|
baseUrl
|
|
|
|
) {
|
|
|
|
return rootUrl.replace(
|
|
|
|
/\$\{(authAdminUrl|authBaseUrl)\}/,
|
2023-07-11 14:03:21 +00:00
|
|
|
joinPath(adminClientBaseUrl, baseUrl),
|
2022-08-22 15:09:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rootUrl?.startsWith("http")) {
|
|
|
|
if (baseUrl) {
|
|
|
|
return joinPath(rootUrl, baseUrl);
|
|
|
|
}
|
|
|
|
return rootUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return baseUrl;
|
|
|
|
};
|