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>
This commit is contained in:
+22
-5
@@ -1,8 +1,10 @@
|
||||
import type { ComponentProps } from "react";
|
||||
import { cookies } from "next/headers";
|
||||
import { HomePageClient } from "@/components/HomePageClient";
|
||||
import { getTodayLocal, formatDateLocal } from "@/lib/env";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
|
||||
const BACKEND_URL = process.env.BACKEND_URL ?? "http://localhost:3001";
|
||||
type WeekData = ComponentProps<typeof HomePageClient>;
|
||||
|
||||
const WEEK_COOKIE = "tcWeek";
|
||||
|
||||
@@ -24,10 +26,25 @@ export default async function HomePage() {
|
||||
const saved = (await cookies()).get(WEEK_COOKIE)?.value;
|
||||
const weekStart = getWeekStart(saved);
|
||||
|
||||
const data = await fetch(
|
||||
`${BACKEND_URL}/api/calendar/week?start=${weekStart}`,
|
||||
{ next: { revalidate: 120 } },
|
||||
).then((r) => r.json());
|
||||
const data = await apiFetch<WeekData>(
|
||||
`/api/calendar/week?start=${weekStart}`,
|
||||
{ revalidate: 120 },
|
||||
);
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<main style={{ minHeight: "100vh", display: "grid", placeItems: "center", padding: 24, background: "var(--color-bg)" }}>
|
||||
<div style={{ maxWidth: 480, textAlign: "center" }}>
|
||||
<h1 style={{ fontSize: "1.2rem", fontWeight: 700, color: "var(--color-text)", marginBottom: 12 }}>
|
||||
Calendar data is unavailable
|
||||
</h1>
|
||||
<p style={{ color: "var(--color-text-muted)", lineHeight: 1.6, fontSize: "0.9rem" }}>
|
||||
We could not reach the backend. Refresh in a moment.
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return <HomePageClient {...data} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user