// Settings from the environment. Only the database path is needed to run. Without the APNs // settings the gateway still serves the watch, it just logs pushes instead of sending them. import { readFileSync } from "node:fs"; import type { ApnsConfig } from "./apns.ts"; export interface Config { port: number; dbPath: string; apns: ApnsConfig | null; } export function loadConfig(env = process.env): Config { const keyId = env.APNS_KEY_ID; const teamId = env.APNS_TEAM_ID; const key = env.APNS_KEY ?? (env.APNS_KEY_PATH ? readFileSync(env.APNS_KEY_PATH, "utf8") : undefined); return { port: Number(env.PORT ?? 8080), dbPath: env.WRISTCODE_DB ?? "data/wristcode.sqlite", apns: keyId && teamId && key ? { keyId, teamId, key: key.replace(/\\n/g, "\n"), topic: env.APNS_TOPIC ?? "org.gbrown.wristcode.watchkitapp" } : null, }; }