// Pages below the site root (the leaderboard) set data-root="../" so API calls still reach /api. const SITE_ROOT = new URL(document.documentElement.dataset.root ?? "./", document.baseURI); export function apiUrl(path) { return new URL(`api/${path}`, SITE_ROOT).href; } async function getJson(path, label) { const response = await fetch(apiUrl(path), { cache: "no-store" }); if (!response.ok) { throw new Error(`${label} failed (${response.status})`); } return response.json(); } export function fetchStats() { return getJson("stats", "Stats request"); } export function fetchLeaderboard() { return getJson("leaderboard", "Leaderboard request"); }