raycer/frontend/public/js/api.js
Spencer Flagg ed3a0d3ea3 Initial commit: raycer accountability PWA
Vanilla HTML/JS/CSS PWA with Dexie offline-first sync, Hono+SQLite backend,
served via nginx reverse-proxy. Two seed goals (no-sugar, no-social-media)
for users ray and cer.

Local dev runs at https://raycer.test via the shared Traefik proxy.
Production deploys to https://raycer.altweb.me on cool2026/personal via
docker-compose.coolify.yaml — see deploy/COOLIFY.md.
2026-04-23 16:45:06 +02:00

22 lines
628 B
JavaScript

const BASE = '/api';
async function req(path, opts = {}) {
const res = await fetch(`${BASE}${path}`, {
headers: { 'content-type': 'application/json' },
...opts,
});
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(`HTTP ${res.status} ${path}: ${text}`);
}
return res.json();
}
export const api = {
health: () => req('/health'),
listGoals: () => req('/goals'),
listCompletionsSince: (since = 0) =>
req(`/completions?since=${encodeURIComponent(since)}`),
putCompletion: (payload) =>
req('/completions', { method: 'PUT', body: JSON.stringify(payload) }),
};