Skip to content
Snippets Groups Projects

roleback to example-ui env code

Merged Mohammad Torkashvand requested to merge fix/fix-env-varaible into develop
3 files
+ 1072
714
Compare changes
  • Side-by-side
  • Inline
Files
3
import process from 'process';
import { Environment, OrchestratorConfig } from '@orchestrator-ui/orchestrator-ui-components';
import process from "process";
import {
Environment,
OrchestratorConfig,
} from "@orchestrator-ui/orchestrator-ui-components";
export const DEFAULT_GRAPHQL_CORE_ENDPOINT =
"http://localhost:8080/api/graphql";
export const DEFAULT_ORCHESTRATOR_API_BASE_URL = "http://localhost:8080/api";
export const DEFAULT_ORCHESTRATOR_WEBSOCKET_URL = "ws://localhost:8080";
export const ENGINE_STATUS_ENDPOINT = "/settings/status";
export const PROCESS_STATUS_COUNTS_ENDPOINT = "/processes/status-counts";
export const PROCESSES_ENDPOINT = "/processes";
export const SUBSCRIPTION_ACTIONS_ENDPOINT = "/subscriptions/workflows";
export const SUBSCRIPTION_PROCESSES_ENDPOINT =
"/processes/process-subscriptions-by-subscription-id";
export const DEFAULT_WORKFLOW_INFORMATION_LINK_URL = "http://localhost:8080";
// Default configurations
export const DEFAULT_GRAPHQL_CORE_ENDPOINT = 'http://localhost:8080/api/graphql';
export const DEFAULT_ORCHESTRATOR_API_BASE_URL = 'http://localhost:8080/api';
export const DEFAULT_ORCHESTRATOR_WEBSOCKET_URL = 'ws://localhost:8080';
export const ENGINE_STATUS_ENDPOINT = '/settings/status';
export const PROCESSES_ENDPOINT = '/processes';
export const SUBSCRIPTION_ACTIONS_ENDPOINT = '/subscriptions/workflows';
export const SUBSCRIPTION_PROCESSES_ENDPOINT = '/processes/process-subscriptions-by-subscription-id';
export const DEFAULT_WORKFLOW_INFORMATION_LINK_URL = 'http://localhost:8080';
interface EnvConfig {
ORCHESTRATOR_GRAPHQL_HOST?: string;
ORCHESTRATOR_GRAPHQL_PATH?: string;
ORCHESTRATOR_API_HOST?: string;
ORCHESTRATOR_API_PATH?: string;
ORCHESTRATOR_WEBSOCKET_URL?: string;
ENVIRONMENT_NAME?: string;
AUTH_ACTIVE?: string;
USE_WEB_SOCKETS?: string;
USE_THEME_TOGGLE?: string;
WORKFLOW_INFORMATION_LINK_URL?: string;
SHOW_WORKFLOW_INFORMATION_LINK?: string;
}
const getEnvValue = (envVar: string | undefined, defaultValue: string): string =>
envVar || defaultValue;
const getBooleanEnvValue = (envVar: string | undefined, defaultValue: boolean): boolean =>
envVar ? envVar.toLowerCase() === 'true' : defaultValue;
// Assemble the Orchestrator configuration from environment variables
export const getInitialOrchestratorConfig = (): OrchestratorConfig => {
const env = process.env as unknown as EnvConfig;
// Construct URLs based on environment or defaults
const orchestratorGraphqlBaseUrl = env.ORCHESTRATOR_GRAPHQL_HOST && env.ORCHESTRATOR_GRAPHQL_PATH
? `${env.ORCHESTRATOR_GRAPHQL_HOST}${env.ORCHESTRATOR_GRAPHQL_PATH}`
: DEFAULT_GRAPHQL_CORE_ENDPOINT;
const orchestratorGraphqlBaseUrl =
process.env.ORCHESTRATOR_GRAPHQL_HOST &&
process.env.ORCHESTRATOR_GRAPHQL_PATH
? `${process.env.ORCHESTRATOR_GRAPHQL_HOST}${process.env.ORCHESTRATOR_GRAPHQL_PATH}`
: DEFAULT_GRAPHQL_CORE_ENDPOINT;
const orchestratorApiBaseUrl = env.ORCHESTRATOR_API_HOST && env.ORCHESTRATOR_API_PATH
? `${env.ORCHESTRATOR_API_HOST}${env.ORCHESTRATOR_API_PATH}`
: DEFAULT_ORCHESTRATOR_API_BASE_URL;
const orchestratorApiBaseUrl =
process.env.ORCHESTRATOR_API_HOST && process.env.ORCHESTRATOR_API_PATH
? `${process.env.ORCHESTRATOR_API_HOST}${process.env.ORCHESTRATOR_API_PATH}`
: DEFAULT_ORCHESTRATOR_API_BASE_URL;
return {
orchestratorApiBaseUrl,
engineStatusEndpoint: orchestratorApiBaseUrl + ENGINE_STATUS_ENDPOINT,
graphqlEndpointCore: orchestratorGraphqlBaseUrl,
processesEndpoint: orchestratorApiBaseUrl + PROCESSES_ENDPOINT,
environmentName: getEnvValue(env.ENVIRONMENT_NAME, Environment.DEVELOPMENT),
subscriptionActionsEndpoint: orchestratorApiBaseUrl + SUBSCRIPTION_ACTIONS_ENDPOINT,
subscriptionProcessesEndpoint: orchestratorApiBaseUrl + SUBSCRIPTION_PROCESSES_ENDPOINT,
orchestratorWebsocketUrl: getEnvValue(env.ORCHESTRATOR_WEBSOCKET_URL, DEFAULT_ORCHESTRATOR_WEBSOCKET_URL),
authActive: getBooleanEnvValue(env.AUTH_ACTIVE, true),
useWebSockets: getBooleanEnvValue(env.USE_WEB_SOCKETS, false),
useThemeToggle: getBooleanEnvValue(env.USE_THEME_TOGGLE, false),
workflowInformationLinkUrl: getEnvValue(env.WORKFLOW_INFORMATION_LINK_URL, DEFAULT_WORKFLOW_INFORMATION_LINK_URL),
showWorkflowInformationLink: getBooleanEnvValue(env.SHOW_WORKFLOW_INFORMATION_LINK, false),
environmentName:
process.env.ENVIRONMENT_NAME ?? Environment.DEVELOPMENT,
// subscriptionActionsEndpoint: orchestratorApiBaseUrl + SUBSCRIPTION_ACTIONS_ENDPOINT,
subscriptionProcessesEndpoint:
orchestratorApiBaseUrl + SUBSCRIPTION_PROCESSES_ENDPOINT,
orchestratorWebsocketUrl:
process.env.ORCHESTRATOR_WEBSOCKET_URL ||
DEFAULT_ORCHESTRATOR_WEBSOCKET_URL,
authActive: process.env.AUTH_ACTIVE?.toLowerCase() != "false",
useWebSockets: process.env.USE_WEB_SOCKETS?.toLowerCase() === "true",
useThemeToggle: process.env.USE_THEME_TOGGLE?.toLowerCase() === "true",
workflowInformationLinkUrl:
process.env.WORKFLOW_INFORMATION_LINK_URL ??
DEFAULT_WORKFLOW_INFORMATION_LINK_URL,
showWorkflowInformationLink:
process.env.SHOW_WORKFLOW_INFORMATION_LINK?.toLowerCase() ===
"true",
};
};
Loading