Revert inventory API to relative paths for Vite dev proxy
CI / basic-check (push) Has been cancelled
CI / basic-check (push) Has been cancelled
This commit is contained in:
@@ -4,22 +4,20 @@ async function handleResponse<T>(response: Response): Promise<T> {
|
||||
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<T>;
|
||||
}
|
||||
|
||||
async function fetchJson<T>(url: string): Promise<T> {
|
||||
const response = await fetch(url, { cache: 'no-store' });
|
||||
return handleResponse<T>(response);
|
||||
}
|
||||
|
||||
export async function fetchInventoryTree(): Promise<InventoryTreeNode[]> {
|
||||
const response = await fetch('http://127.0.0.1:8000/inventory/tree');
|
||||
const data = await handleResponse<ListResponse<InventoryTreeNode>>(response);
|
||||
const data = await fetchJson<ListResponse<InventoryTreeNode>>('/inventory/tree');
|
||||
return data.items;
|
||||
}
|
||||
|
||||
export async function fetchNodeContext(id: string): Promise<NodeContext> {
|
||||
const response = await fetch(`http://127.0.0.1:8000/inventory/nodes/${id}/context`);
|
||||
const data = await handleResponse<EntityResponse<NodeContext>>(response);
|
||||
const data = await fetchJson<EntityResponse<NodeContext>>(`/inventory/nodes/${id}/context`);
|
||||
return data.item;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user