2021-07-15 09:50:01 +00:00
|
|
|
export type Environment = {
|
|
|
|
/** The realm which should be used when signing into the application. */
|
|
|
|
loginRealm: string;
|
|
|
|
/** The URL to the root of the auth server. */
|
|
|
|
authServerUrl: string;
|
|
|
|
/** The URL to the path of the auth server where client requests can be sent. */
|
|
|
|
authUrl: string;
|
|
|
|
/** The URL to the base of the admin console. */
|
|
|
|
consoleBaseUrl: string;
|
2022-11-03 14:06:26 +00:00
|
|
|
/** The URL to resources such as the files in the `public` directory. */
|
2021-07-15 09:50:01 +00:00
|
|
|
resourceUrl: string;
|
|
|
|
/** The name of the master realm. */
|
|
|
|
masterRealm: string;
|
2022-04-05 07:20:00 +00:00
|
|
|
/** The version hash of the auth server. */
|
2021-07-15 09:50:01 +00:00
|
|
|
resourceVersion: string;
|
2021-11-22 11:41:12 +00:00
|
|
|
/** The hash of the commit the Admin UI was built on, useful to determine the exact version the user is running. */
|
|
|
|
commitHash: string;
|
2021-07-15 09:50:01 +00:00
|
|
|
/** Indicates if the application is running as a Keycloak theme. */
|
|
|
|
isRunningAsTheme: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The default environment, used during development.
|
|
|
|
const defaultEnvironment: Environment = {
|
2022-11-03 14:06:26 +00:00
|
|
|
loginRealm: "master",
|
2022-03-06 15:25:37 +00:00
|
|
|
authServerUrl: "http://localhost:8180",
|
|
|
|
authUrl: "http://localhost:8180",
|
|
|
|
consoleBaseUrl: "/admin/master/console/",
|
2021-07-15 09:50:01 +00:00
|
|
|
resourceUrl: ".",
|
|
|
|
masterRealm: "master",
|
|
|
|
resourceVersion: "unknown",
|
2021-11-22 11:41:12 +00:00
|
|
|
commitHash: "unknown",
|
2021-07-15 09:50:01 +00:00
|
|
|
isRunningAsTheme: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Merge the default and injected environment variables together.
|
|
|
|
const environment: Environment = {
|
|
|
|
...defaultEnvironment,
|
|
|
|
...getInjectedEnvironment(),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default environment;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extracts the environment variables that are passed if the application is running as a Keycloak theme.
|
|
|
|
* These variables are injected by Keycloak into the `index.ftl` as a script tag, the contents of which can be parsed as JSON.
|
|
|
|
*/
|
|
|
|
function getInjectedEnvironment(): Record<string, string | number | boolean> {
|
|
|
|
const element = document.getElementById("environment");
|
|
|
|
|
|
|
|
// If the element cannot be found, return an empty record.
|
|
|
|
if (!element?.textContent) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to parse the contents as JSON and return its value.
|
|
|
|
try {
|
|
|
|
return JSON.parse(element.textContent);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Unable to parse environment variables.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, return an empty record.
|
|
|
|
return {};
|
|
|
|
}
|