// Run on the server with Node.js 22+; never embed your key in browser code. const routes = { all: "/lotto/huay", government: "/lotto", hanoi: "/lotto/huay", laos: "/lotto/huay", yeekee: "/lotto/yeekee", stock: "/lotto/stock", thaiyen: "/lotto/thaiyen", }; const category = process.argv[2] ?? "all"; const key = process.env.LOTTO_API_KEY; if (!Object.hasOwn(routes, category) || !key) { console.error("Set LOTTO_API_KEY and choose: " + Object.keys(routes).join(", ")); process.exitCode = 1; } else { const url = new URL("https://api.supapongai.com/api/v1" + routes[category]); if (["hanoi", "laos"].includes(category)) url.searchParams.set("type", category); try { const response = await fetch(url, { headers: { "X-API-KEY": key }, signal: AbortSignal.timeout(30_000), }); if (!response.ok) throw new Error(`HTTP ${response.status}`); const payload = await response.json(); if (payload?.success === false) throw new Error("API returned success=false"); console.log(JSON.stringify(payload, null, 2)); } catch (error) { console.error("Request failed:", error.message); process.exitCode = 1; } }