43 lines
1.6 KiB
JavaScript
43 lines
1.6 KiB
JavaScript
// Frontend Configuration
|
|
// This file handles environment variable configuration for the frontend
|
|
|
|
// Get environment variables (these would be injected by a build tool like Vite)
|
|
// For now, we'll use defaults that can be overridden
|
|
const getEnvVar = (name, defaultValue) => {
|
|
// In a real Vite setup, this would be import.meta.env[name]
|
|
// For now, we'll check if there's a global config object or use defaults
|
|
if (typeof window !== 'undefined' && window.APP_CONFIG && window.APP_CONFIG[name]) {
|
|
return window.APP_CONFIG[name];
|
|
}
|
|
return defaultValue;
|
|
};
|
|
|
|
// API Configuration
|
|
// Default to the same hostname as the frontend, on port 8000 (override via VITE_API_BASE_URL*)
|
|
const _defaultHost = (typeof window !== 'undefined' && window.location?.hostname) || 'localhost';
|
|
const _defaultPort = getEnvVar('VITE_API_BASE_URL_PORT', '8000');
|
|
const _defaultBase = `http://${_defaultHost}:${_defaultPort}`;
|
|
export const API_BASE_URL = getEnvVar('VITE_API_BASE_URL', _defaultBase);
|
|
export const API_BASE_URL_WITH_PREFIX = getEnvVar(
|
|
'VITE_API_BASE_URL_WITH_PREFIX',
|
|
`${_defaultBase}/api`
|
|
);
|
|
|
|
// For file serving (same as API_BASE_URL since files are served from the same server)
|
|
export const API_BASE_URL_FOR_FILES = API_BASE_URL;
|
|
|
|
// Development server configuration
|
|
export const DEV_SERVER_PORT = getEnvVar('VITE_DEV_SERVER_PORT', '8001');
|
|
export const DEV_SERVER_HOST = getEnvVar('VITE_DEV_SERVER_HOST', '127.0.0.1');
|
|
|
|
// Export all config as a single object for convenience
|
|
export const CONFIG = {
|
|
API_BASE_URL,
|
|
API_BASE_URL_WITH_PREFIX,
|
|
API_BASE_URL_FOR_FILES,
|
|
DEV_SERVER_PORT,
|
|
DEV_SERVER_HOST
|
|
};
|
|
|
|
export default CONFIG;
|