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:
@@ -1,11 +1,11 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { PARK_MAP } from "@/lib/parks";
|
||||
import UptimePill from "@/components/charts/UptimePill";
|
||||
import WaitTimeTodayChart from "@/components/charts/WaitTimeTodayChart";
|
||||
import WeeklyStatsChart from "@/components/charts/WeeklyStatsChart";
|
||||
|
||||
const BACKEND_URL = process.env.BACKEND_URL ?? "http://localhost:3001";
|
||||
import { getBackendUrl } from "@/lib/api";
|
||||
|
||||
type Tab = "today" | "7d" | "30d";
|
||||
|
||||
@@ -62,6 +62,20 @@ function parseTab(raw: string | undefined): Tab {
|
||||
return "today";
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
||||
const { id, slug } = await params;
|
||||
const park = PARK_MAP.get(id);
|
||||
if (!park) return { title: "Ride not found | Thoosie Calendar" };
|
||||
const rideName = decodeURIComponent(slug).replace(/-/g, " ");
|
||||
const title = `${rideName} — ${park.shortName} | Thoosie Calendar`;
|
||||
const description = `Live wait time and uptime history for ${rideName} at ${park.name}.`;
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
openGraph: { title, description },
|
||||
};
|
||||
}
|
||||
|
||||
export default async function RideDetailPage({ params, searchParams }: PageProps) {
|
||||
const { id, slug } = await params;
|
||||
const { tab: tabParam } = await searchParams;
|
||||
@@ -71,9 +85,14 @@ export default async function RideDetailPage({ params, searchParams }: PageProps
|
||||
|
||||
const tab = parseTab(tabParam);
|
||||
|
||||
const res = await fetch(`${BACKEND_URL}/api/parks/${id}/rides/${slug}`, {
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
let res: Response;
|
||||
try {
|
||||
res = await fetch(`${getBackendUrl()}/api/parks/${id}/rides/${slug}`, {
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
} catch {
|
||||
return <ErrorState parkId={id} parkName={park.name} />;
|
||||
}
|
||||
|
||||
if (res.status === 404) {
|
||||
return <NoHistoryYet parkId={id} parkName={park.name} slug={slug} />;
|
||||
@@ -83,7 +102,12 @@ export default async function RideDetailPage({ params, searchParams }: PageProps
|
||||
return <ErrorState parkId={id} parkName={park.name} />;
|
||||
}
|
||||
|
||||
const data: ApiResponse = await res.json();
|
||||
let data: ApiResponse;
|
||||
try {
|
||||
data = (await res.json()) as ApiResponse;
|
||||
} catch {
|
||||
return <ErrorState parkId={id} parkName={park.name} />;
|
||||
}
|
||||
const { ride, live, today, last7d, last30d, coverage } = data;
|
||||
|
||||
const last30dUptime = last30d.length
|
||||
|
||||
Reference in New Issue
Block a user