Files
homelab-infra/apps/dashboard/assets/js/api.js
T

28 lines
616 B
JavaScript

const DEFAULT_HEADERS = {
Accept: "application/json",
};
async function fetchJson(path) {
const response = await fetch(path, {
headers: DEFAULT_HEADERS,
cache: "no-store",
});
if (!response.ok) {
throw new Error(`Request failed for ${path}: ${response.status}`);
}
return response.json();
}
export async function fetchDashboardData() {
const [overview, system, services, storage] = await Promise.all([
fetchJson("/api/overview"),
fetchJson("/api/system"),
fetchJson("/api/services"),
fetchJson("/api/storage"),
]);
return { overview, system, services, storage };
}