-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv-loader.js
More file actions
38 lines (33 loc) · 1.21 KB
/
Copy pathenv-loader.js
File metadata and controls
38 lines (33 loc) · 1.21 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
// Simple .env loader for frontend
class EnvLoader {
static async load() {
if (window.ENV && typeof window.ENV === 'object') {
console.info('Environment variables already loaded:', window.ENV);
return;
}
try {
const response = await fetch('.env');
if (!response.ok) {
console.info('No .env file found, using defaults');
return;
}
const text = await response.text();
const env = {};
text.split('\n').forEach(line => {
line = line.trim();
if (line && !line.startsWith('#')) {
const [key, ...valueParts] = line.split('=');
if (key && valueParts.length > 0) {
env[key.trim()] = valueParts.join('=').trim();
}
}
});
window.ENV = env;
console.info('Environment variables loaded from .env:', env);
} catch (error) {
console.info('Could not load .env file:', error.message);
}
}
}
// Load environment variables when script loads
EnvLoader.load();