File size: 1,143 Bytes
d3a497e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { dev } from '$app/environment';
import { env } from '$env/dynamic/public';

export interface ApiConfig {
    baseUrl: string;
    isLocal: boolean;
}

/**
 * Get API configuration based on environment
 */
export function getApiConfig(): ApiConfig {
    // Check for explicit environment variable first
    const apiUrl = env.PUBLIC_API_URL;
    
    if (apiUrl) {
        return {
            baseUrl: apiUrl,
            isLocal: apiUrl.includes('localhost') || apiUrl.includes('127.0.0.1')
        };
    }
    
    // Default behavior: use localhost in dev, production URL in prod
    if (dev) {
        return {
            baseUrl: 'http://localhost:8000',
            isLocal: true
        };
    }
    
    return {
        baseUrl: 'https://dylanebert-3d-arena-backend.hf.space',
        isLocal: false
    };
}

/**
 * Get full API endpoint URL
 */
export function getApiEndpoint(path: string): string {
    const config = getApiConfig();
    return `${config.baseUrl}${path}`;
}

/**
 * Public API endpoints
 */
export const ApiEndpoints = {
    PAIR: '/pair',
    VOTE: '/vote',
    LEADERBOARD: '/leaderboard',
} as const;