diff options
| author | soryu <soryu@soryu.co> | 2025-12-22 04:50:25 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2025-12-23 14:47:18 +0000 |
| commit | 0741a8b8e9a2099c82bff6d6b9ebbce9c07cad53 (patch) | |
| tree | 88cbd5fecb9ca72a04aa07f1a6db4e1a751b1fd7 /makima/frontend/src/lib/api.ts | |
| parent | aee2e4e784afd6d115fb5f7b40284c4efd2da966 (diff) | |
| download | soryu-0741a8b8e9a2099c82bff6d6b9ebbce9c07cad53.tar.gz soryu-0741a8b8e9a2099c82bff6d6b9ebbce9c07cad53.zip | |
Update makima FE to add initial listening system
Diffstat (limited to 'makima/frontend/src/lib/api.ts')
| -rw-r--r-- | makima/frontend/src/lib/api.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/makima/frontend/src/lib/api.ts b/makima/frontend/src/lib/api.ts new file mode 100644 index 0000000..a6f6c3e --- /dev/null +++ b/makima/frontend/src/lib/api.ts @@ -0,0 +1,40 @@ +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; +} |
