-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat: base path support #7625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
feat: base path support #7625
Conversation
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Really looking for this PR to be merged! Thank you, @hsteude. Dear maintainers - please check/merge. |
|
@hsteude I was playing around with your PR. Seems that additional fix is needed. When I run from a custom base path I see the following error: |
docs: improve comment explaining double mounting for reverse proxy support
77978fe to
e393b1f
Compare
@PhantomYdn : Thanks for taking a look into this, good catch! I didn't realize because we tested with our own internal build where the basePath fix is baked in at build time. Added a commit that fixes the regex pattern. Also rebased on dev. Would you mind checking again if it works for you now? |
|
@hsteude It partially helped, but not yet fully solve the issue. The fonts (may be other resources as well) are loaded through JavaScript and still assume hardcoded paths like |
- Install Bun for building OpenCode from source - Clone OpenCode from prokube/opencode fork with base-path PR (#7625) - Build OpenCode with 'bun install' and 'bun run build' - Add --base-path /sn_admin/oc flag to opencode web command - Update health check URL to use base path - Remove nginx rewrite since OpenCode handles base path internally This fixes OpenCode assets (JS/CSS) returning 404 when running behind nginx reverse proxy at /sn_admin/oc/ PR: anomalyco/opencode#7625 TODO: Switch back to npm install when PR is merged to mainline
Add support for running OpenCode behind a reverse proxy with a configurable base path prefix (e.g., /myapp/). - Adds --base-path CLI option, OPENCODE_BASE_PATH env var, and server.basePath config - Rewrites HTML/JS/CSS responses at runtime to include the base path - Wraps history.pushState/replaceState to prepend base path to URLs
|
@hsteude I have solved this problem here: https://github.com/SkyNetCMS/opencode. There are few complexities, like availablility of frontend beyond reverse proxy with fixated opencode version (apparantly "opencode web" proxy all requests to app.opencode.ai and it's posslb to have case when opencode is older and not compatible with frontend) |
Add support for running OpenCode behind a reverse proxy with a configurable base path prefix (e.g.,
/myapp/)Fixes this issue.
Why
When deploying OpenCode with path-based routing, the application needs to serve assets and handle routing under a URL prefix. Without this, OpenCode can only run at the root path.
What it does
--base-pathCLI option,OPENCODE_BASE_PATHenv var, andserver.basePathconfighistory.pushState/replaceStateto prepend base path to URLsDesign decisions
Runtime rewriting: We rewrite content at runtime because the frontend is proxied from
app.opencode.aiand we don't control the build.Regex-based Vite patching: Vite bakes the base path into a function at build time (
function(t){return"/"+t}). Since we don't know the base path until runtime, we patch this via regex. It's not great, but the only alternative would require rebuilding the frontend for each deployment.Double mounting: The app is mounted at both
basePathAND/because some reverse proxies strip the path before forwarding. Without this, requests would 404.No CSP with basePath: We inject inline scripts for the history wrapper, which is incompatible with strict CSP.
Feedback and Ideas are welcome :)