Uh oh!
There was an error while loading. Please reload this page.
feat(server): runtime base path support for reverse proxy deployments - #28326
feat(server): runtime base path support for reverse proxy deployments#28326fabiovincenzi wants to merge 31 commits into
Conversation
The following comment was made by an LLM, it may be inaccurate: Related PRs FoundThis PR (28326) supersedes several earlier attempts at solving the same problem, as noted in the description. Here are the related PRs:
Why they're related:
This PR consolidates all the learnings into a complete implementation with both CLI flag support, server-side request interception, HTML injection, and frontend SolidJS router integration. |
19ffabd to
e2c6334Comparef5d31a8 to
9dc842cCompareKaminariOS
commented
Jun 9, 2026
A really useful feat. |
9b50948 to
bd7fff5Compareawschmeder
commented
Jun 22, 2026
Hello @fabiovincenzi -- I found your open PR while trying to solve a similar issue where the reverse proxy injects a Use caseJupyterHub's Proposed addition to |
…enzi/opencode into feat/base-path-support
fabiovincenzi
commented
Jun 26, 2026
Hey @awschmeder, great suggestion! I've implemented exactly this, the Thanks for the detailed write-up, it made the implementation straightforward! |
# Conflicts: # packages/opencode/src/server/routes/instance/httpapi/server.ts # packages/opencode/src/server/server.ts
…enzi/opencode into feat/base-path-support
fabiovincenzi
commented
Jul 1, 2026
Hi @Hona@Brendonovich, this PR adds base path support for reverse proxy deployments. Would love your feedback when you have a moment! |
# Conflicts: # packages/opencode/src/server/routes/instance/httpapi/server.ts
bcgrillo
commented
Jul 25, 2026
This feature is really useful! I hope they include it. For now, I’m testing it on your branch. Thanks for all your hard work @fabiovincenzi and @awschmeder 💯 |
# Conflicts: # packages/app/src/env.d.ts
…t/base-path-support
…t/base-path-support
KaminariOS
commented
Aug 11, 2026
Why is this PR still not merged? It is a Pareto improvement. |
stackedsax
commented
Aug 19, 2026
@adamdotdevin, @Hona, @Brendonovich, anything we can do to keep this moving? |
xieyucheng123
commented
Aug 26, 2026
Bug: Most frontend API requests ignore |
| Endpoint | Uses /opencode prefix? |
|---|---|
/opencode/api/session?limit=5000&order=desc | ✅ Yes |
/opencode/global/health | ✅ Yes |
/api/health | ❌ No |
/api/event (SSE, polled continuously) | ❌ No |
/api/session/active | ❌ No |
/api/project | ❌ No |
/api/provider | ❌ No |
/api/model | ❌ No |
/api/model/default | ❌ No |
/global/health (initial load) | ❌ No |
Impact
Behind a reverse proxy (e.g. nginx routing /opencode/ → opencode backend), the unprefixed requests hit the wrong backend or return 404. The frontend cannot function properly.
When accessing the server directly (no proxy), the unprefixed requests still work because the server handles both prefixed and unprefixed routes — so this bug is only visible behind a reverse proxy.
Environment
- Built from this PR branch (
feat/base-path-support) - Browser: Chrome
--base-path /opencode
Suggested fix
The base path is correctly applied to the SolidJS Router and some API calls (api/session, global/health), but the majority of API client calls are not using the base path. It looks like the base path injection in the frontend API client is only partially applied — likely some code paths use window.__OPENCODE_BASE_PATH__ while others construct URLs without it.
User xieyucheng123 does not have write permissions |
Issue for this PR
Closes#7624
Type of change
What does this PR do?
Adds a
--base-pathflag (alsoserver.basePathin config) so opencode web works behind a reverse proxy at a prefix likeplatform.com/opencode/.The server strips the prefix before routing, redirects
/opencodeto/opencode/, and returns 404 for anything outside the prefix.The UI picks up the base path via an injected global so the SolidJS router and API calls use the right URLs.
Vite base changed to "./" for relative chunk imports.
Supersedes #7625, #18209, #25513, #23912.
How did you verify your code works?
Built with
bun run --cwd packages/opencode build -- --single, ranopencode web --base-path /opencode.UI loads, assets resolve, API works under prefix, 404 outside it, 301 redirect without trailing slash, no breakage without the flag.
18 unit tests covering normalization, HTML injection, XSS prevention, and CSP hash computation.
Screenshots / recordings
N/A - no visual changes, only routing behavior.
Checklist