Spaces:
Runtime error
Runtime error
Download web/src/lib/api.ts from tarkovski/venorly-api: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/tarkovski/venorly-api/resolve/main/web/src/lib/api.ts
- Command line
-
hf download hf://spaces/tarkovski/venorly-api/web/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/tarkovski/venorly-api/resolve/main/web/src/lib/api.ts
1.05 kB
| import { supabase } from './supabase'; | |
| /** | |
| * Backend API base URL'ini döner. | |
| * - Tarayıcıda: '' (relative path → Vercel proxy üzerinden /api/...) | |
| * - Sunucuda (SSR): NEXT_PUBLIC_API_URL veya localhost fallback | |
| */ | |
| export function getApiUrl(): string { | |
| if (process.env.NEXT_PUBLIC_API_URL) { | |
| return process.env.NEXT_PUBLIC_API_URL; | |
| } | |
| // Tarayıcıda relative path kullan ('') -> Vercel proxy rewrite (/api/...) üzerinden çalışır | |
| if (typeof window !== 'undefined') { | |
| return ''; | |
| } | |
| return 'http://127.0.0.1:8000'; | |
| } | |
| /** | |
| * Auth token'lı fetch wrapper. | |
| * Supabase session varsa Authorization header ekler. | |
| */ | |
| export async function apiFetch( | |
| path: string, | |
| options: RequestInit = {} | |
| ): Promise<Response> { | |
| const { | |
| data: { session }, | |
| } = await supabase.auth.getSession(); | |
| const token = session?.access_token; | |
| const url = `${getApiUrl()}${path}`; | |
| return fetch(url, { | |
| ...options, | |
| headers: { | |
| ...options.headers, | |
| ...(token && { Authorization: `Bearer ${token}` }), | |
| }, | |
| }); | |
| } | |