diff --git a/frontend/src/lib/inventoryApi.ts b/frontend/src/lib/inventoryApi.ts index cfff45b..b1033fa 100644 --- a/frontend/src/lib/inventoryApi.ts +++ b/frontend/src/lib/inventoryApi.ts @@ -4,22 +4,20 @@ async function handleResponse(response: Response): Promise { if (!response.ok) { throw new Error(`API error: ${response.status}`); } - const contentType = response.headers.get('content-type') || ''; - if (!contentType.includes('application/json')) { - const text = await response.text(); - throw new Error(`API returned non-JSON response: ${text.slice(0, 80)}`); - } return response.json() as Promise; } +async function fetchJson(url: string): Promise { + const response = await fetch(url, { cache: 'no-store' }); + return handleResponse(response); +} + export async function fetchInventoryTree(): Promise { - const response = await fetch('http://127.0.0.1:8000/inventory/tree'); - const data = await handleResponse>(response); + const data = await fetchJson>('/inventory/tree'); return data.items; } export async function fetchNodeContext(id: string): Promise { - const response = await fetch(`http://127.0.0.1:8000/inventory/nodes/${id}/context`); - const data = await handleResponse>(response); + const data = await fetchJson>(`/inventory/nodes/${id}/context`); return data.item; }