import { z } from 'zod'; const envSchema = z.object({ PORT: z.coerce.number().default(8096), HOST: z.string().default('0.0.0.0'), DATA_DIR: z.string().default('./data'), STATIC_DIR: z.string().optional(), PUBLIC_URL: z.string().url().default('http://localhost:8096'), // Set when this instance is deployed under a path prefix on a shared domain // (e.g. "/regress" on podsteadr.atobitcoin.io/regress/) rather than at // root. Must match nginx's location block, which must NOT strip the // prefix — the NIP-98 `u` tag the frontend signs includes it, so the // backend needs to see (and route) the same full path. Leave unset ("") to // deploy at root, e.g. its own dedicated host/port. ROUTE_PREFIX: z.string().default(''), NIP98_MAX_SKEW_SECS: z.coerce.number().default(60), SESSION_TTL_DAYS: z.coerce.number().default(30), // Base URL for BTC Map's API — global sync pulls every place worldwide via // the chronological /v4/places endpoint (paginated, incremental via a // stored watermark — see routes/sync.ts), not scoped to any region. // Overridable for tests to point at a mock server instead of the real API. BTCMAP_API_BASE_URL: z.string().url().default('https://api.btcmap.org'), // How close (in meters) a player must be to a place to claim it or link from it. CLAIM_RADIUS_METERS: z.coerce.number().default(40), // Maximum link length, in kilometers — mirrors Ingress's level-scaled link // range (up to ~655km at max level) with a single flat cap instead, since // Regress has no resonator-leveling system to scale it off of. MAX_LINK_DISTANCE_KM: z.coerce.number().default(500), // Claims expire after this many Bitcoin blocks and revert to neutral — // mirrors Ingress's real-world portal decay, but block-height-based // instead of wall-clock, since that's the native "clock" for this game. PORTAL_TIMEOUT_BLOCKS: z.coerce.number().default(2100), BLOCK_HEIGHT_API_URL: z.string().url().default('https://mempool.space/api/blocks/tip/height'), // How often to sweep for and expire timed-out claims. EXPIRY_SWEEP_INTERVAL_MS: z.coerce.number().default(5 * 60 * 1000), }); export type Config = z.infer; export function loadConfig(env: NodeJS.ProcessEnv = process.env): Config { return envSchema.parse(env); }