app/src/config/apiConfig.ts
kcar e5fa002d12 fix: remove hardcoded prod/local browser URLs from app dev bundle
- Create centralized src/config/apiConfig.ts for API_BASE, TLSYNC_URL,
  WHISPERLIVE_URL, and SEARCH_URL resolution
- Fix multiplayerUser.tsx to use VITE_TLSYNC_URL instead of deriving
  from VITE_FRONTEND_SITE_URL (was pointing to prod TLSync)
- Replace all 127.0.0.1:8080 fallbacks with /api (relative path)
- Replace all localhost:8000 fallbacks with VITE_API_BASE || /api
- Remove hardcoded https://api.classroomcopilot.ai production fallbacks
  from transcription store and panel
- Fix axiosConfig.ts to use centralized API config
- Update .env.dev: set VITE_TLSYNC_URL to dev frontend URL
- Update .env.development: fix VITE_SEARCH_URL from localhost to prod
- Add missing env var type declarations to vite-env.d.ts

Fixes: t_73d78fb1
2026-05-28 13:29:47 +01:00

45 lines
1.5 KiB
TypeScript

/**
* Centralized API configuration for Classroom Copilot.
*
* Resolves the API base URL from environment variables with proper fallbacks.
* - In dev: VITE_API_BASE should always be set (e.g., http://192.168.0.64:18000)
* - In production: VITE_API_BASE should be set to the production API URL
* - Fallback: "/api" (relative path, works when API is served from same origin)
*
* IMPORTANT: Never hardcode localhost or 127.0.0.1 as fallbacks - they break
* remote dev access and do not work in containerized environments.
*/
/**
* Primary API base URL. Use this for all API calls.
* Resolved from VITE_API_BASE (preferred) or VITE_API_URL (legacy alias).
*/
export const API_BASE: string =
import.meta.env.VITE_API_BASE ||
import.meta.env.VITE_API_URL ||
"/api";
/**
* TLSync worker URL for tldraw multiplayer.
* Resolved from VITE_TLSYNC_URL (preferred) or derived from VITE_FRONTEND_SITE_URL.
*/
export const TLSYNC_URL: string =
import.meta.env.VITE_TLSYNC_URL ||
(import.meta.env.VITE_FRONTEND_SITE_URL?.startsWith("http")
? `${import.meta.env.VITE_FRONTEND_SITE_URL}/tldraw`
: `https://${import.meta.env.VITE_FRONTEND_SITE_URL}/tldraw`);
/**
* WhisperLive WebSocket URL for live transcription.
* Resolved from VITE_WHISPERLIVE_URL. Must be set in env.
*/
export const WHISPERLIVE_URL: string | undefined =
import.meta.env.VITE_WHISPERLIVE_URL;
/**
* Search proxy URL (searxng).
* Resolved from VITE_SEARCH_URL.
*/
export const SEARCH_URL: string =
import.meta.env.VITE_SEARCH_URL || "/searxng-api/";