From 5896165cfd65de6f34e847b40e7f508ea36966e9 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 13 Jul 2025 21:05:11 -0400 Subject: [PATCH] fix undefined url --- lib/api.ts | 84 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index 1569ed2..3f34706 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -1,36 +1,48 @@ -const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8000'; - - const apiRequest = async (endpoint, options = {}) => { - const { method = 'GET', body = null, token = null } = options; - - const headers = { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - }; - - if (token) { - headers['Authorization'] = `Bearer ${token}`; - } - - const config = { - method, - headers, - }; - - if (body) { - config.body = JSON.stringify(body); - } - - const response = await fetch(`${API_URL}${endpoint}`, config); - - if (!response.ok) { - const errorData = await response.json().catch(() => ({ detail: 'An unknown error occurred' })); - throw new Error(errorData.detail || `HTTP error! status: ${response.status}`); - } - - if (response.headers.get("content-type")?.includes("application/json")) { - return response.json(); - } - - return response; // For non-json responses like video streams - }; \ No newline at end of file +// We still export this for use in components where the raw URL is needed, +// like the