Files
SixFlagsSuperCalendar/backend/src/config.ts
T
josh 5d9daee627
Build and Deploy / Lint, typecheck, test (push) Successful in 30s
Build and Deploy / Build & Push (push) Successful in 1m39s
refactor: production-essentials hardening pass
Backend: structured logger, env-validated config, graceful SIGTERM/SIGINT
shutdown, per-IP rate limiter, per-tier scheduler concurrency latch, error
context on previously-silent catches, compiled-JS Dockerfile stage.

Frontend: lib/api.ts consolidates BACKEND_URL with lazy production-required
check, root + per-segment error.tsx / not-found.tsx / loading.tsx,
generateMetadata on park and ride pages, graceful fallback when backend is
unreachable, Plausible script gated on env vars.

Infra: CI runs lint + typecheck + tests on both packages before docker build,
compose adds healthchecks, log rotation, and memory limits; .env.example
documents every variable.

Cleanup: removed empty app/api/parks/ dir and 0-byte root parks.db, moved
wait-times-urls.txt into docs/, dropped an `as any` cast.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-30 10:17:52 -04:00

26 lines
894 B
TypeScript

/**
* Centralized env parsing — validate at startup, fail fast on bad config.
* Other modules read from the frozen `config` object instead of process.env
* so misconfiguration shows up here, not deep in a request handler.
*/
import { parseStalenessHours } from "../../lib/env";
function parsePort(raw: string | undefined, fallback: number): number {
if (!raw) return fallback;
const n = parseInt(raw, 10);
if (!Number.isFinite(n) || n < 1 || n > 65535) {
throw new Error(`Invalid PORT=${raw}: must be an integer in 1..65535`);
}
return n;
}
export const config = Object.freeze({
port: parsePort(process.env.PORT, 3001),
parkHoursStalenessHours: parseStalenessHours(process.env.PARK_HOURS_STALENESS_HOURS, 72),
nodeEnv: process.env.NODE_ENV ?? "development",
rateLimitPerMin: parsePort(process.env.RATE_LIMIT_PER_MIN, 60),
});
export type Config = typeof config;