feat: add base path support for reverse proxy deployments#25777
feat: add base path support for reverse proxy deployments#25777carsongee wants to merge 1 commit intoanomalyco:devfrom
Conversation
Adds OPENCODE_SERVER_BASE_PATH env var, --base-path CLI flag, and server.basePath config option. When set, injects a <base href> tag into HTML responses so asset references resolve correctly when opencode web is served behind a path-prefixed reverse proxy. The SolidJS Router is also given the base path so client-side navigation stays within the prefix.
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicates FoundThere are existing PRs addressing similar functionality:
Recommendation: Check PR #25513 and #23912 to see if they address the same reverse proxy path prefix issue, particularly around asset URL resolution and the |
|
Closing in favor of the existing PR addressing #7624. |
Closes #25776
What
Adds a base path option so
opencode webworks correctly when served behind a reverse proxy that adds a path prefix.Three ways to configure it:
--base-path /my/prefixCLI flagOPENCODE_SERVER_BASE_PATH=/my/prefixenv varserver.basePathinopencode.jsonWhy
Asset URLs in the built HTML use root-relative paths (
/assets/index-xxx.js). Behind a path-prefixed proxy the browser resolves them against the host root, not the proxy prefix, causing 404s for all JS/CSS.How it works
When
basePathis set, the server injects<base href="/the/prefix/">into every HTML response (both embedded and proxied). Browsers then resolve all asset and navigation URLs relative to that base — no rebuild required. The SolidJS Router reads the<base>element at boot and uses its pathname as itsbaseprop so client-side routing stays within the prefix.Verification
Start with a prefix:
Confirm
curl -s http://localhost:4096/ | grep '<base'returns<base href="/notebook-sessions/abc/ports/4096/">, and that all assets load when accessing via the proxy URL.