env variables handling
This commit is contained in:
36
js/config.js
36
js/config.js
@@ -1,16 +1,36 @@
|
||||
// config.js
|
||||
import { getEnv } from './env-loader.js';
|
||||
import { getEnv, waitForEnv } from './env-loader.js';
|
||||
|
||||
export function getPublicVapidKey() {
|
||||
// Get the VAPID key from environment variables through the env-loader
|
||||
return getEnv('PUBLIC_VAPID_KEY');
|
||||
// Initialize environment variables
|
||||
let envInitialized = false;
|
||||
let initPromise = null;
|
||||
|
||||
// Function to ensure environment variables are loaded
|
||||
export async function ensureEnvLoaded() {
|
||||
if (envInitialized) return;
|
||||
|
||||
if (!initPromise) {
|
||||
initPromise = waitForEnv().then(() => {
|
||||
envInitialized = true;
|
||||
console.log('Environment variables loaded in config.js');
|
||||
});
|
||||
}
|
||||
|
||||
return initPromise;
|
||||
}
|
||||
|
||||
// The VAPID key should not be exposed directly in the source code
|
||||
// Use the getter function instead: getPublicVapidKey()
|
||||
// Initialize immediately
|
||||
ensureEnvLoaded();
|
||||
|
||||
// Direct access to environment variables (synchronous, may return default values if called too early)
|
||||
export function getPublicVapidKey() {
|
||||
return getEnv('PUBLIC_VAPID_KEY');
|
||||
}
|
||||
|
||||
export function getBackendUrl() {
|
||||
return getEnv('BACKEND_URL');
|
||||
}
|
||||
|
||||
// Get backend URL from environment variables
|
||||
export const BACKEND_URL = getEnv('BACKEND_URL');
|
||||
export const FLIC_BUTTON_ID = 'game-button'; // Example ID, might need configuration
|
||||
export const LOCAL_STORAGE_KEY = 'gameTimerData';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user