Skip to content

feat: App - Support setting base URL during build#18209

Open
Ark-kun wants to merge 2 commits intoanomalyco:devfrom
Ark-kun:feat--App---Support-setting-base-URL-to-during--build
Open

feat: App - Support setting base URL during build#18209
Ark-kun wants to merge 2 commits intoanomalyco:devfrom
Ark-kun:feat--App---Support-setting-base-URL-to-during--build

Conversation

@Ark-kun
Copy link

@Ark-kun Ark-kun commented Mar 19, 2026

This is needed to host OpenCode app under under some URL prefix. Usage: Set VITE_BASE_URL env var during build. This automatically sets the base in Vite config. It's also used in routers.
See https://vite.dev/config/shared-options#base

Issue for this PR

Issue: #7624

Type of change

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

What does this PR do?

This change is needed to host OpenCode app under under some URL prefix.
This tiny PR makes it possible to build OpenCode Web App with VITE_BASE_URL="/subdir/" and have it run under http://<host>:<port>/subdir/ instead of root (http://<host>:<port>/).

Set VITE_BASE_URL env var during build. This automatically sets the base in Vite config. Vite generates correct URLs in index.html.
import.meta.env.BASE_URL is also used in routers. See https://vite.dev/config/shared-options#base
You can also set VITE_OPENCODE_SERVER_BASE_URL to specify the base URL prefix for the server.

How did you verify your code works?

% VITE_BASE_URL="/XXX" VITE_OPENCODE_SERVER_BASE_URL="/" bun dev
$ vite
(!) "base" option should start with a slash.

  VITE v7.1.4  ready in 320 ms

  ➜  Local:   http://localhost:3000/XXX

Checklist

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

If you do not follow this template your PR will be automatically rejected.

This is needed to host OpenCode app under under some URL prefix.
This minimal change makes it possible to build OpenCode Web App with VITE_BASE_URL="/subdir/" and have it run under `http://<host>:<port>/subdir/` instead of root (`http://<host>:<port>/`).

Set `VITE_BASE_URL` env var during build. This automatically sets the `base` in Vite config. Vite generates correct URLs in `index.html`.
`import.meta.env.BASE_URL` is also used in routers. See https://vite.dev/config/shared-options#base
You can also set `VITE_OPENCODE_SERVER_BASE_URL` to specify the base URL prefix for the server.

Usage:
```
% VITE_BASE_URL="/XXX" VITE_OPENCODE_SERVER_BASE_URL="/" bun dev
$ vite
(!) "base" option should start with a slash.

  VITE v7.1.4  ready in 320 ms

  ➜  Local:   http://localhost:3000/XXX
```
@Ark-kun Ark-kun requested a review from adamdotdevin as a code owner March 19, 2026 09:04
@github-actions
Copy link
Contributor

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

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.

1 participant