From 2a77bb345eb2e57a4559f961f557657d3e754aba Mon Sep 17 00:00:00 2001 From: xrendan Date: Thu, 28 May 2026 10:23:21 -0600 Subject: [PATCH 1/2] tracker: remap /tracker/api proxy paths for standalone host The Next rewrite blindly forwarded /tracker/api/v1/* to /tracker/api/v1/*, which 404s on the standalone Outcome Tracker host (commitments/departments live at the root, no /api/v1 prefix). Mirror the server-side mapping in lib/tracker-api.ts so client-side SWR calls work against the nelson deploy via NEXT_PUBLIC_TRACKER_API_BASE. --- next.config.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/next.config.ts b/next.config.ts index 97f0a3b..60bd2c9 100644 --- a/next.config.ts +++ b/next.config.ts @@ -21,6 +21,31 @@ const nextConfig: NextConfig = { ]; }, async rewrites() { + const trackerBase = process.env.NEXT_PUBLIC_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 From c707b65f5b1b8b7196d18128d09951778367c171 Mon Sep 17 00:00:00 2001 From: xrendan Date: Thu, 28 May 2026 10:26:52 -0600 Subject: [PATCH 2/2] tracker: drop NEXT_PUBLIC_TRACKER_API_BASE, use TRACKER_API_BASE only The var is only read server-side (next.config.ts rewrites + lib/tracker-api.ts), and the upstream URL is never exposed to the browser via the proxy. The NEXT_PUBLIC_ prefix was misleading. Consolidate on a single TRACKER_API_BASE env var. --- Dockerfile | 2 -- README.md | 3 +-- next.config.ts | 2 +- src/lib/tracker-api.ts | 3 +-- 4 files changed, 3 insertions(+), 7 deletions(-) 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 60bd2c9..2db294b 100644 --- a/next.config.ts +++ b/next.config.ts @@ -21,7 +21,7 @@ const nextConfig: NextConfig = { ]; }, async rewrites() { - const trackerBase = process.env.NEXT_PUBLIC_TRACKER_API_BASE; + 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 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";