/** * API Configuration * Centralized configuration for API endpoints and settings */ import { getBaseDomain, isRootDomain } from '../utils/domain'; // Determine API base URL based on environment const getApiBaseUrl = (): string => { // In production, this would be set via environment variable if (import.meta.env.VITE_API_URL) { return import.meta.env.VITE_API_URL; } // Development: build API URL dynamically based on current domain const baseDomain = getBaseDomain(); const protocol = window.location.protocol; // For localhost or lvh.me, use port 8000 const isDev = baseDomain === 'localhost' || baseDomain === 'lvh.me'; const port = isDev ? ':8000' : ''; return `${protocol}//api.${baseDomain}${port}`; }; export const API_BASE_URL = getApiBaseUrl(); /** * Extract subdomain from current hostname * Returns null if on root domain or invalid subdomain */ export const getSubdomain = (): string | null => { const hostname = window.location.hostname; const parts = hostname.split('.'); // Root domain (no subdomain) - no business context if (isRootDomain()) { return null; } // Has subdomain if (parts.length > 1) { const subdomain = parts[0]; // Exclude special subdomains if (['www', 'api', 'platform'].includes(subdomain)) { return subdomain === 'platform' ? null : subdomain; } return subdomain; } return null; }; /** * Check if current page is platform site */ export const isPlatformSite = (): boolean => { const hostname = window.location.hostname; return hostname.startsWith('platform.'); }; /** * Check if current page is business site */ export const isBusinessSite = (): boolean => { const subdomain = getSubdomain(); return subdomain !== null && subdomain !== 'platform'; };