From d16dcfe66efca5b24204f8444273b5f1f158200a Mon Sep 17 00:00:00 2001 From: Perplexity Bot Date: Tue, 4 Aug 2026 19:53:12 +0000 Subject: [PATCH] Use direct backend URLs for inventory API and guard JSON parsing --- frontend/src/lib/inventoryApi.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/inventoryApi.ts b/frontend/src/lib/inventoryApi.ts index b123ccb..cfff45b 100644 --- a/frontend/src/lib/inventoryApi.ts +++ b/frontend/src/lib/inventoryApi.ts @@ -4,17 +4,22 @@ 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; } export async function fetchInventoryTree(): Promise { - const response = await fetch('/inventory/tree'); + const response = await fetch('http://127.0.0.1:8000/inventory/tree'); const data = await handleResponse>(response); return data.items; } export async function fetchNodeContext(id: string): Promise { - const response = await fetch(`/inventory/nodes/${id}/context`); + const response = await fetch(`http://127.0.0.1:8000/inventory/nodes/${id}/context`); const data = await handleResponse>(response); return data.item; }