From 78b149983d3414b1a797e8b71050f9bfc539c1fa Mon Sep 17 00:00:00 2001 From: Shinei Nouzen <157171073+Shineii86@users.noreply.github.com> Date: Wed, 29 Jul 2026 07:22:14 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20Auto-detect=20local=20server=20in=20tes?= =?UTF-8?q?t.js=20=E2=80=94=20falls=20back=20to=20live=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index 9239fab..465aa74 100644 --- a/test.js +++ b/test.js @@ -13,7 +13,24 @@ * ======= • ======= • ======= • ======= • =======• ======= */ -const BASE = process.env.API_URL || "https://anikototvapi.vercel.app/api"; +const LIVE_API = "https://anikototvapi.vercel.app/api"; +const LOCAL_API = "http://localhost:4444/api"; + +let BASE = process.env.API_URL || LIVE_API; + +async function detectBase() { + if (process.env.API_URL) return; + try { + const res = await fetch(`${LOCAL_API}/health`, { signal: AbortSignal.timeout(2000) }); + if (res.ok) { + BASE = LOCAL_API; + console.log("📡 Detected local server — using localhost:4444\n"); + return; + } + } catch (_) {} + BASE = LIVE_API; + console.log("📡 No local server found — using live API\n"); +} const tests = [ // Core endpoints @@ -147,7 +164,8 @@ async function fetchJson(url) { } async function runAll() { - console.log(`\n🧪 Running ${tests.length} tests...\n`); + await detectBase(); + console.log(`🧪 Running ${tests.length} tests...\n`); console.log(`📡 API: ${BASE}\n`); // ---- FEATURE: Resolve dynamic test dependencies ----