/** * Environment Configuration for Baby Tracker App * * Loads from remote API with local fallback defaults. * Other modules should await window.envReady before reading window.env. */ const CONFIG_API_URL = 'https://config.ooyy.de5.net/api/kv/babyday'; const CONFIG_API_AUTH = 'c2RFV3dlMzIzMmZGVjplZGl0b3I='; const CONFIG_TIMEOUT_MS = 5000; // Default fallback values (used when remote config is unavailable) window.env = { SUPABASE_URL: 'https://ovehbuxmhknxhuhetigc.supabase.co', SUPABASE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im92ZWhidXhtaGtueGh1aGV0aWdjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjM1OTU1NjMsImV4cCI6MjA3OTE3MTU2M30.XuThuzSrDGhgFK5d82lqVy_ClyDy0xkYUxKe1ego2gs', IMGBED_API: 'https://cf-imgbed-31z.pages.dev/upload?authCode=9YW0fVuUFAoF8KhGLrnTPCk', GROW_API_URL: 'https://jsondata.888653.xyz/grow', // Set to '' or null to disable AI assessment AI_API_URL: 'https://aiask.888653.xyz', // Baby birth date (YYYY/MM/DD) BIRTH_DATE: '2025/03/09' }; const CONFIG_KEYS = [ 'SUPABASE_URL', 'SUPABASE_KEY', 'IMGBED_API', 'GROW_API_URL', 'AI_API_URL', 'BIRTH_DATE' ]; async function loadRemoteConfig() { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), CONFIG_TIMEOUT_MS); try { const response = await fetch(CONFIG_API_URL, { method: 'GET', headers: { Authorization: `Bearer ${CONFIG_API_AUTH}`, 'Content-Type': 'application/json' }, signal: controller.signal }); if (!response.ok) { console.warn('Remote config unavailable, using defaults:', response.status); return false; } const config = await response.json(); let applied = 0; for (const key of CONFIG_KEYS) { if (config[key] !== undefined && config[key] !== null && config[key] !== '') { window.env[key] = config[key]; applied++; } } console.log(`Remote config loaded (${applied} keys applied)`); return true; } catch (error) { if (error.name === 'AbortError') { console.warn('Remote config timed out, using defaults'); } else { console.warn('Remote config failed, using defaults:', error.message); } return false; } finally { clearTimeout(timeoutId); } } // Modules should await this before depending on final env values window.envReady = loadRemoteConfig();