Files
vsc-adda/src/http.ts
T

22 lines
475 B
TypeScript

const URL = 'https://www.gymcontrol.se/global/checkedin/checkedin.php?uid=9094';
export async function getVisitorCount(): Promise<number> {
const response = await fetch(URL, {
signal: AbortSignal.timeout(5000)
});
const raw = await response.text();
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const text = raw.trim();
if (!/^\d+$/.test(text)) {
throw new Error(`Invalid response: ${JSON.stringify(text)}`);
}
return Number(text);
}