Skip to content

feat: support serving opencode from a subpath#25513

Open
ramonpaolo wants to merge 2 commits intoanomalyco:devfrom
ramonpaolo:feat/subpath-support
Open

feat: support serving opencode from a subpath#25513
ramonpaolo wants to merge 2 commits intoanomalyco:devfrom
ramonpaolo:feat/subpath-support

Conversation

@ramonpaolo
Copy link
Copy Markdown

@ramonpaolo ramonpaolo commented May 3, 2026

Issue for this PR

Closes #13847

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This adds native basePath support for the OpenCode server and web UI so it can be served cleanly from a subpath such as /opencode/ instead of assuming /.

On the server side, requests can now arrive either with the configured prefix still present or already stripped by a reverse proxy, and both cases resolve to the same internal route tree. On the frontend side, the app shell now emits relative asset URLs, the HTML response exposes the effective mount path, and the browser uses that path when building API, SSE, WebSocket, and router URLs.

These changes work because they keep the existing API paths unchanged internally and treat the subpath as a transport/runtime concern at the server boundary and browser bootstrap boundary. That makes the legacy Hono backend, the experimental HttpApi backend, and the built app all agree on the same effective mount path.

How did you verify your code works?

  • Ran npm exec -- bun test test/server/base-path.test.ts test/cli/network.test.ts test/server/httpapi-ui.test.ts in packages/opencode
  • Ran npm exec -- bun typecheck in packages/opencode
  • Ran npm exec -- bun test --preload ./happydom.ts ./src/utils/base-path.test.ts ./src/index-shell.test.ts ./src/vite-config.test.ts in packages/app
  • Ran npm exec -- bun typecheck in packages/app
  • Ran npm exec -- bun run build in packages/app
  • Confirmed the emitted packages/app/dist/index.html uses relative asset URLs such as ./assets/...
  • Build "localcode" based on this commit on docker and execute the command "opencode web --hostname 127.0.0.1 --port "4096" --base-path /opencode" and put a NGINX on front with:
location /opencode/ {
      proxy_pass http://127.0.0.1:4096;
      proxy_http_version 1.1;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
    } 

Screenshots / recordings

(See the URL on browser, that starts with "http://localhost/opencode")
image
image
image

Don't have visual UI changes; this PR changes mount-path, assets, routing and request behavior.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@ramonpaolo ramonpaolo requested a review from adamdotdevin as a code owner May 3, 2026 01:50
@ramonpaolo ramonpaolo changed the title feat: support serving opencode from a subpath [WIP] feat: support serving opencode from a subpath May 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #23912: "feat: make opencode web embeddable in iframes at a subpath"
#23912

Why it's related: This PR also addresses serving OpenCode from a subpath and handling mount paths. Both PRs are concerned with supporting non-root path deployment, though this one may have a specific focus on iframe embedding. Worth checking if #23912 is closed/merged and whether it covers the same scope as the current PR #25513.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

Hey! Your PR title [WIP] feat: support serving opencode from a subpath doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@ramonpaolo ramonpaolo force-pushed the feat/subpath-support branch 2 times, most recently from fca84c9 to 66c4164 Compare May 3, 2026 02:06
@ramonpaolo ramonpaolo force-pushed the feat/subpath-support branch from 3ff6dae to ed7583b Compare May 3, 2026 02:51
@ramonpaolo ramonpaolo changed the title [WIP] feat: support serving opencode from a subpath feat: support serving opencode from a subpath May 3, 2026
@ramonpaolo ramonpaolo force-pushed the feat/subpath-support branch 2 times, most recently from 04764af to f71d546 Compare May 3, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Opencode web change /sub-dir/ in url location?

1 participant