| function normalizeApiBase(raw: string): string { | |
| const trimmed = String(raw || '').trim().replace(/\/+$/, '') | |
| if (!trimmed) return '' | |
| // Accept both "https://host" and "https://host/api" forms. | |
| // Our code appends "/api/..." paths, so strip a trailing "/api" to avoid "/api/api". | |
| return trimmed.replace(/\/api$/, '') | |
| } | |
| export const API_BASE = normalizeApiBase( | |
| process.env.API_URL || process.env.NEXT_PUBLIC_API_URL || '' | |
| ) | |
| export const isApiConfigured = Boolean(process.env.API_URL || process.env.NEXT_PUBLIC_API_URL); | |
| export function requireApiBase() { | |
| if (!API_BASE) { | |
| throw new Error('API URL yapılandırılmamış. API_URL (veya NEXT_PUBLIC_API_URL) tanımlayın.'); | |
| } | |
| return API_BASE; | |
| } | |
| /** Standardised User-Agent for outgoing server-side fetches */ | |
| export const USER_AGENT = 'borsa-nextjs/1.0' | |
| /** Browser-like User-Agent for sites that reject bot-like headers (e.g. Yahoo Finance) */ | |
| export const BROWSER_USER_AGENT = | |
| 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36' | |
| export function apiUrl(path: string) { | |
| const base = requireApiBase(); | |
| if (!path) return base; | |
| return `${base}${path.startsWith('/') ? '' : '/'}${path}`; | |
| } | |