Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Expand All @@ -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

Expand Down
30 changes: 26 additions & 4 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*",
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/lib/tracker-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Loading