diff --git a/Dockerfile b/Dockerfile index e39d565..5b2de63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,10 +20,8 @@ ENV NEXT_TELEMETRY_DISABLED=1 # Build-time configuration — forwarded into `next build` so server-side # fetches during static generation hit the correct API host. ARG TRACKER_API_BASE -ARG NEXT_PUBLIC_TRACKER_API_BASE ARG NEXT_PUBLIC_SITE_URL ENV TRACKER_API_BASE=$TRACKER_API_BASE -ENV NEXT_PUBLIC_TRACKER_API_BASE=$NEXT_PUBLIC_TRACKER_API_BASE ENV NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL RUN pnpm run build diff --git a/README.md b/README.md index 41879f5..1900c1d 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Required in production: | Variable | Purpose | Notes | |----------|---------|-------| | `NEXT_PUBLIC_SITE_URL` | Canonical/OG/sitemap base URL | e.g. `https://buildcanada.com`. Used by `layout.tsx`, `sitemap.ts`, `robots.ts`, `lib/api/config.ts`, and JSON-LD. | -| `NEXT_PUBLIC_TRACKER_API_BASE` | Backend host for `/tracker/api/*` rewrites | Set to wherever the Outcomes Tracker API is served. Falls back to `https://www.buildcanada.com`, which will loop after cutover. | +| `TRACKER_API_BASE` | Backend host for `/tracker/api/*` rewrites and server-side fetches | Set to wherever the Outcomes Tracker API is served. Falls back to `https://www.buildcanada.com`, which will loop after cutover. Server-only — never exposed to the browser. | | `YORK_FACTORY_API_URL` | York Factory CMS base URL | Defaults to `https://yorkfactory.buildcanada.com/api/v1`. Override per environment. | | `LUMA_API_KEY` | Luma events list (`/api/events`) | Without this the homepage events list silently returns empty. | @@ -79,7 +79,6 @@ Recommended: | `NEXT_PUBLIC_POSTHOG_TOKEN` | PostHog analytics + client-side exception capture (`error.tsx` boundaries report here). | | `NEXT_PUBLIC_POSTHOG_HOST` | PostHog UI host. Defaults to `https://us.i.posthog.com`. | | `NEXT_PUBLIC_GA_MEASUREMENT_ID` | Google Analytics. Loader is conditional — omit to disable. | -| `TRACKER_API_BASE` | Server-only override for tracker API base (read in `lib/tracker-api.ts` when no public var is set). | ## Deployment notes diff --git a/next.config.ts b/next.config.ts index 97f0a3b..2db294b 100644 --- a/next.config.ts +++ b/next.config.ts @@ -21,6 +21,31 @@ const nextConfig: NextConfig = { ]; }, async rewrites() { + const trackerBase = process.env.TRACKER_API_BASE; + + // Default (buildcanada.com): Rails API is mounted under /tracker, paths + // pass through unchanged. Standalone host (e.g. nelson deploy): commitments + // and departments live at the root (strip /tracker/api/v1), while + // dashboard/burndown stay under /api (strip /tracker only). Mirrors the + // server-side mapping in src/lib/tracker-api.ts. + const trackerRewrites = trackerBase + ? [ + { + source: "/tracker/api/v1/:path*", + destination: `${trackerBase}/:path*`, + }, + { + source: "/tracker/api/:path*", + destination: `${trackerBase}/api/:path*`, + }, + ] + : [ + { + source: "/tracker/api/:path*", + destination: `https://www.buildcanada.com/tracker/api/:path*`, + }, + ]; + return [ { source: "/ph/static/:path*", @@ -34,10 +59,7 @@ const nextConfig: NextConfig = { source: "/ph/decide", destination: "https://us.i.posthog.com/decide", }, - { - source: "/tracker/api/:path*", - destination: `${process.env.NEXT_PUBLIC_TRACKER_API_BASE || "https://www.buildcanada.com"}/tracker/api/:path*`, - }, + ...trackerRewrites, ]; }, // Required to support PostHog trailing slash API requests diff --git a/src/lib/tracker-api.ts b/src/lib/tracker-api.ts index b06da8d..c9b65d4 100644 --- a/src/lib/tracker-api.ts +++ b/src/lib/tracker-api.ts @@ -11,8 +11,7 @@ // /departments.json) while dashboard/burndown still live under /api/*. We // strip the /api/v1 prefix on those two endpoints and skip the /tracker // prepend. -const EXPLICIT_BASE = - process.env.TRACKER_API_BASE || process.env.NEXT_PUBLIC_TRACKER_API_BASE; +const EXPLICIT_BASE = process.env.TRACKER_API_BASE; const API_BASE = EXPLICIT_BASE || "https://www.buildcanada.com";