From 783a0257ea53b8bb6962f51a8c0fef3a2b16553f Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 11 Jan 2026 05:52:19 +0000 Subject: [PATCH] Changes --- src/components/dev/ApiDevTools.tsx | 32 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/components/dev/ApiDevTools.tsx b/src/components/dev/ApiDevTools.tsx index 2a67052..76ceefa 100644 --- a/src/components/dev/ApiDevTools.tsx +++ b/src/components/dev/ApiDevTools.tsx @@ -46,15 +46,30 @@ function clearLogs() { notifyListeners(); } -// Intercept fetch +// Intercept fetch (dev only) +const isDev = import.meta.env.DEV; const originalFetch = window.fetch; -window.fetch = async function (input, init) { - const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url; - - // Only log API calls - if (!url.includes("/api/")) { - return originalFetch.apply(this, [input, init]); - } + +// Avoid patching multiple times during HMR +const globalAny = window as unknown as { __gatehouseFetchPatched?: boolean }; +if (isDev && !globalAny.__gatehouseFetchPatched) { + globalAny.__gatehouseFetchPatched = true; + + window.fetch = async function (input, init) { + const url = + typeof input === "string" ? input : input instanceof URL ? input.href : input.url; + + // Log calls that look like our backend API (support both absolute + relative base URLs) + const shouldLog = + url.includes("/api/") || + url.includes("/api/v1") || + url.includes("/auth/") || + url.includes("/users/") || + url.includes("/org/"); + + if (!shouldLog) { + return originalFetch.apply(this, [input, init]); + } const id = crypto.randomUUID(); const method = init?.method || "GET"; @@ -133,6 +148,7 @@ window.fetch = async function (input, init) { throw err; } }; +} // Check if we're in development mode const isDev = import.meta.env.DEV;