const API_CONFIG = { local: { http: "http://localhost:8080", ws: "ws://localhost:8080", }, production: { http: "https://api.makima.jp", ws: "wss://api.makima.jp", }, } as const; type Environment = "local" | "production"; function detectEnvironment(): Environment { // Check if explicitly set via env var const envOverride = import.meta.env.VITE_API_ENV as Environment | undefined; if (envOverride && (envOverride === "local" || envOverride === "production")) { return envOverride; } // Auto-detect based on hostname if (typeof window !== "undefined") { const hostname = window.location.hostname; if (hostname === "localhost" || hostname === "127.0.0.1") { return "local"; } } return "production"; } const env = detectEnvironment(); export const API_BASE = API_CONFIG[env].http; export const WS_BASE = API_CONFIG[env].ws; export const LISTEN_ENDPOINT = `${WS_BASE}/api/v1/listen`; export function getEnvironment(): Environment { return env; }