modified version

This commit is contained in:
Stan
2026-04-21 23:26:13 +02:00
parent e7127f3215
commit bdd06105dd
46 changed files with 1250 additions and 5248 deletions
+8 -12
View File
@@ -1,13 +1,17 @@
/*
* API communication module. Centralizes fetch calls and service-worker
* registration so network details stay out of rendering and state logic.
* API communication module. Centralizes fetch calls so network details stay
* out of rendering and state logic. All JSON traffic from the frontend goes
* through `fetchJson()`, which prepends the versioned base path and unwraps
* structured error responses into regular thrown errors.
*/
import { API_BASE } from './constants.js';
/*
* Generic JSON fetcher. All frontend API calls pass through this function so
* error handling, header defaults, and base path are consistent everywhere.
* Generic JSON fetcher. Prepends the API base path when the caller passes a
* relative path, forwards headers, and parses the response body on success.
* Non-2xx responses raise an `Error` whose message is the server's `message`
* field when present, otherwise a generic status-code fallback.
*/
export async function fetchJson(path, options = {}) {
const url = path.startsWith('http') ? path : `${API_BASE}${path}`;
@@ -40,11 +44,3 @@ export async function fetchJson(path, options = {}) {
return response.json();
}
export function registerServiceWorker() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').catch((error) => {
console.error('Service worker registration failed', error);
});
}
}