feat: serve base path#2889
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| }); | ||
| } | ||
|
|
||
| let filePath = path.resolve(staticRoot, staticRelativePath); |
There was a problem hiding this comment.
Static paths ignore base prefix
High Severity
The catch-all static handler maps HttpServerRequest.toURL’s pathname directly onto files under staticRoot without removing the configured basePath. With a non-root prefix, requests like /custom/assets/… resolve to staticRoot/custom/…, so assets are missing and the handler often serves rewritten index.html instead of JS/CSS, breaking the served UI.
Reviewed by Cursor Bugbot for commit a29e812. Configure here.
There was a problem hiding this comment.
not a case, app is mounted on basePath already
can add special handling (404?) if needed
| if (config.devUrl && isLoopbackHostname(url.value.hostname)) { | ||
| return HttpServerResponse.redirect(resolveDevRedirectUrl(config.devUrl, url.value), { | ||
| status: 302, | ||
| }); |
There was a problem hiding this comment.
Dev redirect keeps base prefix
Medium Severity
Loopback dev redirects copy the incoming request pathname onto devUrl unchanged. After mounting under a non-root basePath, that pathname includes the serve prefix, so the Vite dev server receives URLs it does not own and redirects fail or 404 when devUrl is set alongside a custom prefix.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit a29e812. Configure here.
There was a problem hiding this comment.
dev mode out of scope
ApprovabilityVerdict: Needs human review New feature introducing configurable base path across the entire stack (server, web, mobile). Two unresolved review comments identify bugs: static file serving and dev redirects don't properly strip the base path prefix, which would break the UI when deployed under a non-root path. You can customize Macroscope's approvability policy. Learn more. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 73c0214. Configure here.


What Changed
Feature to specify custom (instead of just root
/) base path when running t3 serve.Caveat: dev mode was left out of scope intentionally.
Why
In order to host multiple t3code instances on single domain.
About index.html paths rewriting: I consider using JSX and fully-generated index.html via
renderToStaticMarkup, but it would look less focused, can be implemented in separate PR if needed.UI Changes
2026-05-31.19.52.59.mov
Checklist
Note
Add configurable base path support for serving the app under a URL prefix
NormalizedBasePath,ROOT_BASE_PATH, andnormalizeBasePathinpackages/shared/src/basePath.tsas the canonical base path type shared across packages.--base-pathCLI flag andT3CODE_BASE_PATHenv var; the resolvedbasePathis stored inServerConfigShapeand propagated throughout the server.config.basePathinapps/server/src/server.tsand rewritesindex.htmlasset URLs to use the base path before serving static files.baseto an empty string so built assets use relative paths, and configures TanStack Router with the runtime-derivedBASE_PATH./; WebSocket connection URLs point to<basePath>/rather than/ws.Macroscope summarized 0548816.
Note
Medium Risk
Changes auth cookie scope, pairing/startup URLs, and WebSocket paths; mis-set basePath could break login and RPC until config matches the reverse proxy.
Overview
Adds configurable URL base path so T3 can run under a path prefix (e.g.
/custom) on one host, not only at/.Server:
basePathis resolved from--base-path/T3CODE_BASE_PATH(via sharednormalizeBasePath), stored onServerConfig, and used to prefix the HTTP router (router.prefixed(config.basePath)). Staticindex.htmlrewritessrc/hrefasset paths to include the prefix. Auth session cookies use path{basePath}/; pairing and headless URLs point at{basePath}/pairwith the prefix in connection strings.Clients: Web derives
BASE_PATHat runtime and passes it to TanStack Router; mobile and shared helpers build API/attachment URLs under the prefix. WebSocket RPC uses{basePath}/ws(and minted WS URLs align with the HTTP base path). Vitebase: ""keeps built assets relative for subpath deploys.Not in scope: dev-mode base path (per PR description).
Reviewed by Cursor Bugbot for commit 0548816. Bugbot is set up for automated code reviews on this repo. Configure here.