Repository navigation
feat: let the client be served from a sub-path - #16
Closed
RohanReddy44 wants to merge 1 commit into
Closed
RohanReddy44 wants to merge 1 commit into
RohanReddy44 wants to merge 1 commit into
Conversation
It assumed it owned the origin root. Assets, fonts, config.json and the API were all absolute from /, so behind a shared domain at /experience every one of them 404d — and the config failure was silent, because an unreachable config.json falls back to the bundled defaults. Subdomains would avoid all of this, but a deployment with several apps behind one proxy cannot always have them, and a reference client should not require one. Assets are relative now (vite base: "./"), and the container rewrites <base href> from BASE_PATH at start-up, using the base image's envsubst template hook and sub_filter. One image serves from / or from /experience/ with no rebuild. CONFIG_URL and the API paths resolve against document.baseURI for the same reason. Two things this turned up that would each have looked like a different bug: - the router matched against the origin root, so every route 404d under a prefix while the page itself loaded. It now takes its basepath from the same <base href> - six icon paths in the header and recording controls were absolute strings, so only those images broke Verified both ways against the built image behind a second nginx acting as the edge proxy: at /experience/ and at /, every asset, font, config.json and the rendered page. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Superseded by the simpler build-time approach — see the replacement PR. This one resolved the base path at container start so one image could serve any path; that costs a fragile |
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.
The client assumed it owned the origin root. Behind a shared domain at
/experience, assets, fonts,config.jsonand the API were all absolute from/and every one of them 404'd.Subdomains avoid all of this, but a box running several apps behind one proxy cannot always have them, and a reference client should not require one.
How it works
One image, any mount path, no rebuild:
Assets are relative (
vite base: "./"), and the container rewrites the<base href>inindex.htmlat start-up using the base image'senvsubsttemplate hook plussub_filter.CONFIG_URLand the API paths resolve againstdocument.baseURIfor the same reason.BASE_PATHunset leaves everything at the root exactly as before.nginx.confbecomesnginx.conf.templateso the entrypoint can substitute the variable. I checked thatenvsubstdoes not eat nginx's own$uriand$cache_control— it only substitutes variables that exist in the environment.Two things this turned up
Each would have looked like a different bug:
The router matched against the origin root, so under a prefix the page loaded, the config resolved, React mounted — and then every route 404'd. It now takes its
basepathfrom the same<base href>.Six icon paths were absolute strings in the header and recording controls, so only those images broke while everything else worked.
Verified both ways
Against the built image with a second nginx container acting as the edge proxy — at
/experience/and at/, withBASE_PATHset and unset:/experience///chatrouteconfig.jsonbrand/logo.pngassets/settings.svgfonts/poppins-400.ttfScreenshotted at the sub-path to confirm the icons and fonts actually render, not just return 200.
Worth knowing operationally
nginx resolves a
proxy_passhostname once at config load. Restart the app container and the proxy keeps the old address until it is reloaded — I hit a 502 from exactly this while testing, and it looks like the app is down when it is not.Not included
docker-compose.deploy.ymlis left untracked, as you asked. TheBASE_PATHknob is documented in the README and wired into the repo's owndocker-compose.yml.🤖 Generated with Claude Code