fix: let self-hosted web builds bake their own public URL - #2267
Open
fancyHeat wants to merge 1 commit into
Open
fix: let self-hosted web builds bake their own public URL#2267fancyHeat wants to merge 1 commit into
fancyHeat wants to merge 1 commit into
Conversation
The web Dockerfile hardcodes NEXT_PUBLIC_WEB_URL=http://localhost:3000. Next inlines NEXT_PUBLIC_* into the client bundle, so that value reaches the browser no matter what WEB_URL or CAP_URL says at runtime: share links, embeds, oEmbed and the CORS allowlist all use localhost on a self-hosted build. Back the ENV with an ARG of the same default so a build can pass --build-arg NEXT_PUBLIC_WEB_URL=... without changing the published image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
apps/web/Dockerfilehardcodes:ENV NEXT_PUBLIC_WEB_URL=http://localhost:3000Next inlines
process.env.NEXT_PUBLIC_*into the client bundle at build time, so this value reaches the browser regardless of whatWEB_URL/CAP_URLsays at runtime.packages/env/build.tsresolvesNEXT_PUBLIC_WEB_URLasprocess.env.WEB_URL ?? process.env.NEXT_PUBLIC_WEB_URL, which fixes the server side, but inside a client chunkprocess.env.WEB_URLisundefinedand the fallback is whatever the Dockerfile baked. Anything client-side that readsbuildEnv.NEXT_PUBLIC_WEB_URL(for examplecomponents/LinkifiedText.tsx, and the origin list seeded inutils/cors.ts) therefore seeshttp://localhost:3000on a self-hosted build.A self-hoster cannot fix this with
.envalone: dotenv does not override a variable already present in the environment, and the Dockerfile'sENVputs it there beforenext buildruns.Fix
Back the
ENVwith anARGcarrying the same default:Passing nothing is a no-op, so the published
ghcr.io/capsoftware/cap-webimage is unchanged. Anyone building the image themselves can pass--build-arg NEXT_PUBLIC_WEB_URL=https://cap.example.comand get the right origin in the browser bundle.Also adds a short note to the self-hosting docs explaining the runtime vs build-time split, since
CAP_URLlooks like it should be enough and is not.Validation
docker build --check -f apps/web/Dockerfile .reports only the pre-existingJSONArgsRecommendedwarning on theCMDline.localhost:3000.The PR appears safe to merge and preserves existing image behavior when no build argument is supplied.
Summary
NEXT_PUBLIC_WEB_URLDocker build argument and exposes it during the Next.js build.Reviews (1) · Last reviewed commit: "fix: let self-hosted web builds bake the..."