Skip to content

Commit aa6d525

Browse files
committed
refactor: simplify environment variable handling by removing window.ENV initialization
1 parent 0eb1142 commit aa6d525

File tree

1 file changed

+5
-78
lines changed

1 file changed

+5
-78
lines changed

ichub-frontend/src/services/EnvironmentService.ts

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@
2020
* SPDX-License-Identifier: Apache-2.0
2121
********************************************************************************/
2222

23-
/// <reference types="vite/client" />
24-
25-
// Extend Window interface for runtime environment variables
26-
declare global {
27-
interface Window {
28-
ENV?: {
29-
REQUIRE_HTTPS_URL_PATTERN?: string;
30-
ICHUB_BACKEND_URL?: string;
31-
PARTICIPANT_ID?: string;
32-
GOVERNANCE_CONFIG?: string;
33-
DTR_POLICIES_CONFIG?: string;
34-
}
35-
}
36-
}
37-
3823
// Types for governance configuration
3924
export interface GovernanceConstraint {
4025
leftOperand: string;
@@ -60,70 +45,13 @@ export interface GovernanceConfig {
6045
policies: GovernancePolicy[];
6146
}
6247

63-
/**
64-
* Ensures window.ENV is properly initialized
65-
* This function can be called to guarantee ENV is available before accessing it
66-
*/
67-
const ensureWindowEnvInitialized = () => {
68-
if (!window.ENV) {
69-
console.warn('window.ENV not found, initializing with fallback values');
70-
window.ENV = {
71-
REQUIRE_HTTPS_URL_PATTERN: import.meta.env.VITE_REQUIRE_HTTPS_URL_PATTERN || 'false',
72-
ICHUB_BACKEND_URL: import.meta.env.VITE_ICHUB_BACKEND_URL || '',
73-
PARTICIPANT_ID: import.meta.env.VITE_PARTICIPANT_ID || '',
74-
GOVERNANCE_CONFIG: import.meta.env.VITE_GOVERNANCE_CONFIG || '[]',
75-
DTR_POLICIES_CONFIG: import.meta.env.VITE_DTR_POLICIES_CONFIG || '[]'
76-
};
77-
}
78-
};
79-
80-
export const isRequireHttpsUrlPattern = () => {
81-
ensureWindowEnvInitialized();
82-
return window?.ENV?.REQUIRE_HTTPS_URL_PATTERN !== 'false';
83-
};
48+
export const isRequireHttpsUrlPattern = () =>
49+
import.meta.env.VITE_REQUIRE_HTTPS_URL_PATTERN !== 'false';
8450

85-
export const getIchubBackendUrl = () => {
86-
ensureWindowEnvInitialized();
87-
88-
// Debug: Log what's available
89-
90-
91-
92-
93-
94-
// First try to get from window.ENV (runtime injection via Helm charts), then fallback to build-time env
95-
const backendUrl = window?.ENV?.ICHUB_BACKEND_URL ||
96-
import.meta.env.VITE_ICHUB_BACKEND_URL;
97-
98-
99-
100-
if (!backendUrl) {
101-
console.warn('❌ ICHUB_BACKEND_URL not configured. Ensure environment variable is set via Helm chart or build configuration.');
102-
}
103-
104-
return backendUrl;
105-
};
106-
export const getParticipantId = () => {
107-
ensureWindowEnvInitialized();
108-
109-
// Debug: Log what's available
110-
111-
112-
113-
114-
// First try to get from window.ENV (runtime injection via Helm charts), then fallback to build-time env
115-
const participantId = window?.ENV?.PARTICIPANT_ID ||
116-
import.meta.env.VITE_PARTICIPANT_ID;
117-
118-
// Use fallback value if no participant ID is configured
119-
const resolvedId = participantId ?? 'BPNL0000000093Q7';
120-
121-
122-
return resolvedId;
123-
};
51+
export const getIchubBackendUrl = () => import.meta.env.VITE_ICHUB_BACKEND_URL ?? '';
52+
export const getParticipantId = () => import.meta.env.VITE_PARTICIPANT_ID ?? 'BPNL0000000093Q7';
12453

12554
export const getGovernanceConfig = (): GovernanceConfig[] => {
126-
ensureWindowEnvInitialized();
12755
try {
12856
// First try to get from window.ENV (runtime injection), then fallback to import.meta.env
12957
const configStr = window?.ENV?.GOVERNANCE_CONFIG || import.meta.env.VITE_GOVERNANCE_CONFIG;
@@ -136,7 +64,6 @@ export const getGovernanceConfig = (): GovernanceConfig[] => {
13664
};
13765

13866
export const getDtrPoliciesConfig = (): GovernancePolicy[] => {
139-
ensureWindowEnvInitialized();
14067
try {
14168
// First try to get from window.ENV (runtime injection), then fallback to import.meta.env
14269
const configStr = window?.ENV?.DTR_POLICIES_CONFIG || import.meta.env.VITE_DTR_POLICIES_CONFIG;
@@ -216,4 +143,4 @@ const EnvironmentService = {
216143
getDtrPoliciesConfig
217144
};
218145

219-
export default EnvironmentService;
146+
export default EnvironmentService;

0 commit comments

Comments
 (0)