WIP: Save current work before CHORUS rebrand
- Agent roles integration progress - Various backend and frontend updates - Storybook cache cleanup 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
95
frontend/src/config/api.ts
Normal file
95
frontend/src/config/api.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* API Configuration
|
||||
* Centralizes API endpoint configuration and environment handling
|
||||
*/
|
||||
|
||||
// Get base URL from environment with smart fallbacks
|
||||
export const getApiBaseUrl = (): string => {
|
||||
// Production environment
|
||||
if (import.meta.env.PROD) {
|
||||
return import.meta.env.VITE_API_BASE_URL || 'https://hive.home.deepblack.cloud';
|
||||
}
|
||||
|
||||
// Development environment - prefer environment variable
|
||||
const envUrl = import.meta.env.VITE_API_BASE_URL;
|
||||
if (envUrl) {
|
||||
return envUrl;
|
||||
}
|
||||
|
||||
// Development fallback - detect if we're running in docker
|
||||
const hostname = window.location.hostname;
|
||||
|
||||
// If we're on the production domain, use production API
|
||||
if (hostname === 'hive.home.deepblack.cloud') {
|
||||
return 'https://hive.home.deepblack.cloud';
|
||||
}
|
||||
|
||||
// If we're on localhost, try to detect the backend port
|
||||
if (hostname === 'localhost' || hostname === '127.0.0.1') {
|
||||
// Check if backend is running on standard development port
|
||||
return 'http://localhost:8089'; // Dev backend port (avoiding filebrowser on 8088)
|
||||
}
|
||||
|
||||
// Docker container or other environments
|
||||
return 'http://localhost:8087'; // Production backend port
|
||||
};
|
||||
|
||||
// Get WebSocket URL from environment with smart fallbacks
|
||||
export const getWebSocketUrl = (): string => {
|
||||
// Production environment
|
||||
if (import.meta.env.PROD) {
|
||||
return import.meta.env.VITE_WS_BASE_URL || 'https://hive.home.deepblack.cloud';
|
||||
}
|
||||
|
||||
// Development environment
|
||||
const envUrl = import.meta.env.VITE_WS_BASE_URL;
|
||||
if (envUrl) {
|
||||
return envUrl;
|
||||
}
|
||||
|
||||
// Smart fallback based on current hostname
|
||||
const hostname = window.location.hostname;
|
||||
|
||||
if (hostname === 'hive.home.deepblack.cloud') {
|
||||
return 'https://hive.home.deepblack.cloud';
|
||||
}
|
||||
|
||||
if (hostname === 'localhost' || hostname === '127.0.0.1') {
|
||||
return 'http://localhost:8089'; // Dev backend port (avoiding filebrowser on 8088)
|
||||
}
|
||||
|
||||
return 'http://localhost:8087'; // Production backend port
|
||||
};
|
||||
|
||||
// Debug configuration
|
||||
export const isDebugMode = (): boolean => {
|
||||
return import.meta.env.VITE_ENABLE_DEBUG_MODE === 'true' || import.meta.env.DEV;
|
||||
};
|
||||
|
||||
// Development mode detection
|
||||
export const isDevMode = (): boolean => {
|
||||
return import.meta.env.VITE_DEV_MODE === 'true' || import.meta.env.DEV;
|
||||
};
|
||||
|
||||
// Log level configuration
|
||||
export const getLogLevel = (): string => {
|
||||
return import.meta.env.VITE_LOG_LEVEL || (import.meta.env.DEV ? 'debug' : 'warn');
|
||||
};
|
||||
|
||||
// API configuration object
|
||||
export const apiConfig = {
|
||||
baseURL: getApiBaseUrl(),
|
||||
websocketURL: getWebSocketUrl(),
|
||||
debug: isDebugMode(),
|
||||
dev: isDevMode(),
|
||||
logLevel: getLogLevel(),
|
||||
timeout: 30000, // 30 seconds
|
||||
retries: 3,
|
||||
};
|
||||
|
||||
// Log configuration in development
|
||||
if (import.meta.env.DEV) {
|
||||
console.log('🔧 API Configuration:', apiConfig);
|
||||
}
|
||||
|
||||
export default apiConfig;
|
||||
Reference in New Issue
Block a user