|
|
import { dev } from '$app/environment'; |
|
|
import { env } from '$env/dynamic/public'; |
|
|
|
|
|
export interface ApiConfig { |
|
|
baseUrl: string; |
|
|
isLocal: boolean; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function getApiConfig(): ApiConfig { |
|
|
|
|
|
const apiUrl = env.PUBLIC_API_URL; |
|
|
|
|
|
if (apiUrl) { |
|
|
return { |
|
|
baseUrl: apiUrl, |
|
|
isLocal: apiUrl.includes('localhost') || apiUrl.includes('127.0.0.1') |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
if (dev) { |
|
|
return { |
|
|
baseUrl: 'http://localhost:8000', |
|
|
isLocal: true |
|
|
}; |
|
|
} |
|
|
|
|
|
return { |
|
|
baseUrl: 'https://dylanebert-3d-arena-backend.hf.space', |
|
|
isLocal: false |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function getApiEndpoint(path: string): string { |
|
|
const config = getApiConfig(); |
|
|
return `${config.baseUrl}${path}`; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const ApiEndpoints = { |
|
|
PAIR: '/pair', |
|
|
VOTE: '/vote', |
|
|
LEADERBOARD: '/leaderboard', |
|
|
} as const; |
|
|
|