Add base kubernetes support 2

This commit is contained in:
Urtzi Alfaro
2025-09-27 12:10:43 +02:00
parent 63a3f9c77a
commit 222f945466
50 changed files with 648 additions and 160 deletions

View File

@@ -10,6 +10,7 @@
* React Query doesn't replace HTTP clients - it manages data fetching/caching/sync
*/
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
import { getApiUrl } from '../../config/runtime';
export interface ApiError {
message: string;
@@ -55,7 +56,7 @@ class ApiClient {
config: AxiosRequestConfig;
}> = [];
constructor(baseURL: string = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000/api/v1') {
constructor(baseURL: string = getApiUrl() + '/api/v1') {
this.baseURL = baseURL;
this.client = axios.create({

View File

@@ -0,0 +1,62 @@
// Runtime configuration for Kubernetes deployments
// This allows environment variables to be injected at container startup
interface RuntimeConfig {
VITE_API_URL: string;
VITE_APP_TITLE: string;
VITE_APP_VERSION: string;
}
declare global {
interface Window {
__RUNTIME_CONFIG__?: RuntimeConfig;
}
}
// Types are defined in vite-env.d.ts
// Get configuration from runtime or fall back to build-time environment variables
function getRuntimeConfig(): RuntimeConfig {
// First try to get from window (injected at runtime in Kubernetes)
if (typeof window !== 'undefined' && window.__RUNTIME_CONFIG__) {
return window.__RUNTIME_CONFIG__;
}
// Fall back to build-time environment variables (development/local)
return {
VITE_API_URL: import.meta.env.VITE_API_URL || 'http://localhost:8000',
VITE_APP_TITLE: import.meta.env.VITE_APP_TITLE || 'PanIA Dashboard',
VITE_APP_VERSION: import.meta.env.VITE_APP_VERSION || '1.0.0',
};
}
export const config = getRuntimeConfig();
// Helper function to get the API base URL
export function getApiUrl(): string {
return config.VITE_API_URL;
}
// Helper function to get app title
export function getAppTitle(): string {
return config.VITE_APP_TITLE;
}
// Helper function to get app version
export function getAppVersion(): string {
return config.VITE_APP_VERSION;
}
// Helper to check if running in Kubernetes
export function isKubernetesEnvironment(): boolean {
return typeof window !== 'undefined' && !!window.__RUNTIME_CONFIG__;
}
// Debug function to log current configuration
export function logConfig(): void {
console.log('Current configuration:', {
...config,
isKubernetes: isKubernetesEnvironment(),
source: isKubernetesEnvironment() ? 'runtime' : 'build-time'
});
}

14
frontend/src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_API_URL: string
readonly VITE_API_BASE_URL: string
readonly VITE_APP_TITLE: string
readonly VITE_APP_VERSION: string
readonly VITE_ENVIRONMENT: string
// more env variables...
}
interface ImportMeta {
readonly env: ImportMetaEnv
}