api: reconfigered api handling

This commit is contained in:
Yordan Simeonov
2025-10-20 18:45:01 +02:00
parent d0194f0dc2
commit 98a2067b8d
9 changed files with 112 additions and 295 deletions

View File

@@ -16,7 +16,8 @@ export async function getAutoComplete(
const url = `${DISCOVER_BASE}/autoComplete?q=${encodeURIComponent(
query
)}&limit=${limit}`;
const res = await fetch(url, { signal });
const apiKey = process.env.EXPO_PUBLIC_API_KEY;
const res = await fetch(url, { signal, headers: { 'Content-Type': 'application/json', "X-API-Key": apiKey ?? "", } });
if (!res.ok) throw new Error("AutoComplete failed " + res.status);
const data: unknown = await res.json();
if (!Array.isArray(data)) return [];