SPB Git

spb/earth-now Public License

earth-now.co — real-time planetary dashboard: live world metrics modeled, not streamed.

TypeScript 93% Shell 2.3% SQL 1.4% JavaScript 1.3% Dockerfile 1.2% CSS 0.8%
992 B · 32 lines typescript
Raw Blame History
1/**2 * earth-now.co3 * Author:  Simon-Pierre Boucher4 * Contact: contact@spboucher.ai5 * File:    apps/api/src/pollers/poller.ts6 * Purpose: Shared RT-poller plumbing — env gate, timeout-bounded JSON fetch, handle type7 */89export interface PollerHandle {10  stop(): void;11}1213export const NOOP_POLLER: PollerHandle = { stop: () => undefined };1415/** RT pollers run unless explicitly disabled (tests, offline dev). */16export function pollersEnabled(): boolean {17  return process.env.ENABLE_RT_POLLERS !== "0";18}1920/** GET a JSON document with a hard timeout; throws on HTTP/network/abort errors. */21export async function fetchJson(url: string, timeoutMs = 10_000): Promise<unknown> {22  const res = await fetch(url, {23    signal: AbortSignal.timeout(timeoutMs),24    headers: {25      accept: "application/json",26      "user-agent": "earth-now.co/0.1 (contact@spboucher.ai)",27    },28  });29  if (!res.ok) throw new Error(`HTTP ${res.status} from ${url}`);30  return (await res.json()) as unknown;31}32