File size: 1,234 Bytes
396c1dd
 
 
 
 
 
 
 
 
656ac31
 
 
518ca05
656ac31
518ca05
 
 
656ac31
518ca05
 
 
f79ab06
656ac31
 
 
 
 
 
 
f79ab06
518ca05
 
 
f79ab06
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
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}`;
}