fix(docker): restore NEXT_PUBLIC_APP_URL build arg with dummy fallback#4665
Conversation
getBaseUrl() in lib/core/utils/urls is evaluated at module load during next build's page-data collection and throws if NEXT_PUBLIC_APP_URL is unset. PR #4658 removed the build arg, breaking the Docker build at the "/_not-found" page-data collection step. Restore the dummy localhost fallback (mirroring DATABASE_URL). The CORS fix from #4658 is preserved: next.config.ts no longer reads NEXT_PUBLIC_APP_URL at build time, and no module-level expression captures getBaseUrl() — every caller invokes it at request time, where getEnv() reads the deployed container env. The dummy localhost value cannot leak into runtime CORS response headers. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryLow Risk Overview Adds clarifying comments that this value is only a build-time fallback and should not affect production CORS behavior. Reviewed by Cursor Bugbot for commit 19a9821. Configure here. |
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Greptile SummaryRestores
Confidence Score: 5/5Safe to merge — the change is a targeted one-liner that restores the build-time dummy value needed to unblock Docker image builds without reintroducing the CORS regression fixed in #4658. The Dockerfile change is minimal and self-contained: it restores a single ARG/ENV pair scoped exclusively to the builder stage. The runtime code paths (getEnv, generateRuntimeCSP, proxy.ts) all read env vars lazily at request time, so the localhost placeholder cannot surface in a deployed container. The claim that next.config.ts no longer derives CORS headers from this variable is confirmed by reading the file — the headers block that caused the original bug is absent. The pre-existing CSP side effect (env.NEXT_PUBLIC_APP_URL baked into buildTimeCSPDirectives) is additive and benign. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Docker builder stage\nARG NEXT_PUBLIC_APP_URL=http://localhost:3000\nENV NEXT_PUBLIC_APP_URL=..."] --> B["next build\n(page-data collection)"]
B --> C["getBaseUrl() called\nduring module eval\n— reads process.env at build time\n→ returns localhost:3000, no throw"]
B --> D[".next/standalone artifact\nbuilt successfully"]
D --> E["Runner stage\n(no NEXT_PUBLIC_APP_URL ENV)"]
E --> F["Container starts\nOperator provides runtime\nNEXT_PUBLIC_APP_URL=https://prod-url"]
F --> G["Server-side getEnv()\nreads process.env at request time\n→ returns https://prod-url ✓"]
F --> H["Client-side getEnv()\nreads window.__ENV via PublicEnvScript\n→ returns https://prod-url ✓"]
F --> I["proxy.ts generateRuntimeCSP()\nreads getEnv() at request time\n→ CORS uses https://prod-url ✓"]
Reviews (1): Last reviewed commit: "chore(docker): trim verbose comment on b..." | Re-trigger Greptile |
Summary
ARG NEXT_PUBLIC_APP_URLfrom the Dockerfile. That brokenext buildin the Docker image:getBaseUrl()inapps/sim/lib/core/utils/urls.tsthrows ifNEXT_PUBLIC_APP_URLis unset, and it's evaluated at module load during page-data collection (fails at/_not-found).DATABASE_URLpattern).Why this is safe (CORS fix from #4658 still holds)
The original bug was
next.config.tsreadingNEXT_PUBLIC_APP_URLat build time and baking it into static API CORS headers. #4658 removed that headers block. This change only restores a build-time arg so module evaluation succeeds; it does not reintroduce build-time CORS resolution:next.config.tsno longer readsNEXT_PUBLIC_APP_URLat build timeproxy.tscallsgetEnv('NEXT_PUBLIC_APP_URL')at request timegetBaseUrl()(verified by grep) — every caller invokes it lazilyhttp://localhost:3000only exists inside the build environmentTest plan
/_not-foundpage-data collection failure)NEXT_PUBLIC_APP_URLenv var serves correctAccess-Control-Allow-Origin(not localhost)