mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 10:55:10 +00:00
feat: Auto-detect local server in test.js — falls back to live API
This commit is contained in:
@@ -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 = [
|
const tests = [
|
||||||
// Core endpoints
|
// Core endpoints
|
||||||
@@ -147,7 +164,8 @@ async function fetchJson(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function runAll() {
|
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`);
|
console.log(`📡 API: ${BASE}\n`);
|
||||||
|
|
||||||
// ---- FEATURE: Resolve dynamic test dependencies ----
|
// ---- FEATURE: Resolve dynamic test dependencies ----
|
||||||
|
|||||||
Reference in New Issue
Block a user