// ── This module's own API bindings ──────────────────────────────────────── // // Core hands out the request PRIMITIVE and nothing above it (MODULE_API.md // §3.5): same-origin `/api/v1`, cookies included, JSON in and out, and an // `ApiError` thrown on any non-2xx. The paths are this module's, because the // routes at the other end are — `server/router/**` in this repo serves them. // // **Do not build your own fetch wrapper.** The primitive is what carries the // session cookie, the CSRF handling and the error shape core's `ErrorState` // knows how to render. A module that calls `fetch` directly gets none of that // and finds out one page at a time. // // Keeping the bindings in one file, ordered the way the routers are, is // convention rather than contract — but the two halves of every call live in // different directories and nothing checks them against each other, so anything // that makes a mismatch easy to see is worth doing. import rg from './core.js' const { request: req, BASE } = rg.api // ── public ──────────────────────────────────────────────────────────────── // Token-free, same-origin reads. Paths are relative to `/api/v1`, so this hits // `/api/v1/public/rust/servers` — the route `server/router/public/rust.router.js` // registers under the `/rust` prefix `module.json` declares. export const servers = { list: () => req('/public/rust/servers'), } // ── player ──────────────────────────────────────────────────────────────── // The same list, on the authenticated tier. It exists so that per-player detail // can be added at an address clients are already calling; today the two answers // are identical and the server delegates to one model so they cannot drift. export const playerServers = { list: () => req('/player/rust/servers'), } // ── admin ───────────────────────────────────────────────────────────────── // **`sidecarToken` goes up and never comes back.** The list answers `hasToken`, // and a save that omits the field leaves the stored credential alone — so an // admin form must send it only when the operator typed one, rather than sending // its own empty field on every save. export const admin = { listServers: () => req('/admin/rust/servers'), saveServer: (id, body) => req(`/admin/rust/servers/${encodeURIComponent(id)}`, { method: 'PUT', body }), deleteServer: (id) => req(`/admin/rust/servers/${encodeURIComponent(id)}`, { method: 'DELETE' }), testServer: (id) => req(`/admin/rust/servers/${encodeURIComponent(id)}/test`, { method: 'POST' }), } // Exported for the rare caller that needs the base itself — an ``, a // download link, an EventSource. Reach for `request` first. export { BASE } export default { servers, playerServers, admin, BASE }