2024-05-20 15:48:51 +02:00
|
|
|
import {
|
|
|
|
nameOfTheGlobal,
|
|
|
|
basenameOfTheKeycloakifyResourcesDir
|
|
|
|
} from "keycloakify/bin/shared/constants";
|
2024-02-11 10:36:50 +01:00
|
|
|
import { assert } from "tsafe/assert";
|
2024-02-09 17:52:26 +01:00
|
|
|
|
|
|
|
/**
|
2024-06-03 18:28:34 +02:00
|
|
|
* This is an equivalent of process.env.PUBLIC_URL that you can use in Webpack projects.
|
2024-02-09 17:52:26 +01:00
|
|
|
* This works both in your main app and in your Keycloak theme.
|
|
|
|
*/
|
|
|
|
export const PUBLIC_URL = (() => {
|
|
|
|
const kcContext = (window as any)[nameOfTheGlobal];
|
|
|
|
|
2024-02-11 10:36:50 +01:00
|
|
|
if (kcContext === undefined || process.env.NODE_ENV === "development") {
|
|
|
|
assert(
|
|
|
|
process.env.PUBLIC_URL !== undefined,
|
|
|
|
`If you use keycloakify/PUBLIC_URL you should be in Webpack and thus process.env.PUBLIC_URL should be defined`
|
|
|
|
);
|
|
|
|
|
|
|
|
return process.env.PUBLIC_URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${kcContext.url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}`;
|
2024-02-09 17:52:26 +01:00
|
|
|
})();
|