89 lines
2.4 KiB
TypeScript
Executable file
89 lines
2.4 KiB
TypeScript
Executable file
/// <reference types="vite/client" />
|
|
|
|
/**
|
|
* Environment variable helpers for API client configuration
|
|
* Supports both Vite (import.meta.env) and Node.js (process.env) environments
|
|
*/
|
|
|
|
/**
|
|
* Get the API base URL from environment variables
|
|
* Falls back to development URL if not specified
|
|
*/
|
|
export function getApiUrl(): string {
|
|
// Check Vite environment first (browser/Vite apps)
|
|
if (typeof import.meta !== 'undefined' && import.meta.env) {
|
|
return import.meta.env.VITE_API_URL || 'http://localhost:4002';
|
|
}
|
|
|
|
// Fallback to Node.js environment (server-side or tests)
|
|
if (typeof process !== 'undefined' && process.env) {
|
|
return process.env.VITE_API_URL || process.env.API_URL || 'http://localhost:4002';
|
|
}
|
|
|
|
// Default fallback
|
|
return 'http://localhost:4002';
|
|
}
|
|
|
|
/**
|
|
* Get the application name from environment variables
|
|
*/
|
|
export function getAppName(): string {
|
|
if (typeof import.meta !== 'undefined' && import.meta.env) {
|
|
return import.meta.env.VITE_APP_NAME || 'unknown';
|
|
}
|
|
|
|
if (typeof process !== 'undefined' && process.env) {
|
|
return process.env.VITE_APP_NAME || process.env.APP_NAME || 'unknown';
|
|
}
|
|
|
|
return 'unknown';
|
|
}
|
|
|
|
/**
|
|
* Check if running in development mode
|
|
*/
|
|
export function isDevelopment(): boolean {
|
|
if (typeof import.meta !== 'undefined' && import.meta.env) {
|
|
return import.meta.env.MODE === 'development' || import.meta.env.DEV === true;
|
|
}
|
|
|
|
if (typeof process !== 'undefined' && process.env) {
|
|
return process.env.NODE_ENV === 'development';
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Check if running in production mode
|
|
*/
|
|
export function isProduction(): boolean {
|
|
if (typeof import.meta !== 'undefined' && import.meta.env) {
|
|
return import.meta.env.MODE === 'production' || import.meta.env.PROD === true;
|
|
}
|
|
|
|
if (typeof process !== 'undefined' && process.env) {
|
|
return process.env.NODE_ENV === 'production';
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get environment variable value with optional fallback
|
|
*/
|
|
export function getEnv(key: string, fallback?: string): string | undefined {
|
|
// Try Vite environment
|
|
if (typeof import.meta !== 'undefined' && import.meta.env) {
|
|
const value = import.meta.env[key];
|
|
if (value !== undefined) {return String(value);}
|
|
}
|
|
|
|
// Try Node.js environment
|
|
if (typeof process !== 'undefined' && process.env) {
|
|
const value = process.env[key];
|
|
if (value !== undefined) {return value;}
|
|
}
|
|
|
|
return fallback;
|
|
}
|