-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
81 lines (68 loc) · 2.32 KB
/
Copy pathconfig.js
File metadata and controls
81 lines (68 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Configuration management
class Config {
constructor() {
// Default values
this.defaults = {
host: 'localhost',
port: '5000',
apiEndpoint: '/api/records',
useProxy: true
};
this.config = this.loadConfig();
}
loadConfig() {
const config = { ...this.defaults };
// Try to load from .env file (if available)
if (window.ENV) {
config.host = window.ENV.API_HOST || config.host;
config.port = window.ENV.API_PORT || config.port;
config.apiEndpoint = window.ENV.API_ENDPOINT || config.apiEndpoint;
config.useProxy = window.ENV.USE_PROXY === 'true' || config.useProxy;
}
// Override with URL parameters (for testing)
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('host')) config.host = urlParams.get('host');
if (urlParams.get('port')) config.port = urlParams.get('port');
if (urlParams.get('endpoint')) config.apiEndpoint = urlParams.get('endpoint');
// Override with localStorage (for persistence)
const savedConfig = localStorage.getItem('apiConfig');
if (savedConfig) {
try {
const parsed = JSON.parse(savedConfig);
Object.assign(config, parsed);
} catch (e) {
console.warn('Failed to parse saved config:', e);
}
}
return config;
}
saveConfig() {
localStorage.setItem('apiConfig', JSON.stringify(this.config));
}
get baseUrl() {
// In Kubernetes, use relative URLs through nginx proxy
if (this.config.useProxy !== false) {
return '';
}
return `http://${this.config.host}:${this.config.port}`;
}
get apiUrl() {
return `${this.baseUrl}${this.config.apiEndpoint}`;
}
get healthUrl() {
// Use /health proxy endpoint in Kubernetes
if (this.config.useProxy !== false) {
return '/health';
}
return `${this.baseUrl}/`;
}
updateConfig(newConfig) {
Object.assign(this.config, newConfig);
this.saveConfig();
}
getConfig() {
return { ...this.config };
}
}
// Global config instance
window.appConfig = new Config();