Files
smoothschedule/frontend/src/api/config.ts
poduck 4cd6610f2a Fix double /api/ prefix in API endpoint calls
When VITE_API_URL=/api, axios baseURL is already set to /api. However, all endpoint calls included the /api/ prefix, creating double paths like /api/api/auth/login/.

Removed /api/ prefix from 81 API endpoint calls across 22 files:
- src/api/auth.ts - Fixed login, logout, me, refresh, hijack endpoints
- src/api/client.ts - Fixed token refresh endpoint
- src/api/profile.ts - Fixed all profile, email, password, MFA, sessions endpoints
- src/hooks/*.ts - Fixed all remaining API calls (users, appointments, resources, etc)
- src/pages/*.tsx - Fixed signup and email verification endpoints

This ensures API requests use the correct path: /api/auth/login/ instead of /api/api/auth/login/

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 15:27:57 -05:00

69 lines
1.8 KiB
TypeScript

/**
* 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';
};