Skip to content

Add serveStaticAsset for custom routing and a TanStack Start SSR example - #3

Merged
nicu-chiciuc merged 7 commits into
mainfrom
nicu-serve-static-asset-custom-routing
Oct 11, 2026
Merged

nicu-chiciuc merged 7 commits into
mainfrom
nicu-serve-static-asset-custom-routing

Conversation

@nicu-chiciuc

@nicu-chiciuc nicu-chiciuc commented Oct 11, 2026 •

Copy link
Copy Markdown

Same branch as upstream get-convex/static-hosting#41. A push to this branch updates both PRs.

  • serveStaticAsset serves one static file from a custom HTTP route, so an app can choose its own routing and server-side rendering fallback.
  • upload --preview-name uploads to a named preview deployment.
  • example-ssr shows TanStack Start SSR on Convex HTTP actions.

This PR does not depend on the asset retention PR. The two merge in either order without conflicts.

Merge with a merge commit, not a squash, so the fork history still matches the upstream PR.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

nicu-chiciuc and others added 7 commits September 26, 2026 22:08
Forward `--preview-name <name>` to every `convex run` the uploader makes, so
static files can be uploaded to a named preview deployment. It cannot be
combined with `--prod`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the lookup and response building into an internal `serveAsset` that
returns null when no file matches. `registerStaticRoutes` keeps the path
decoding, prefix stripping, `/` -> `/index.html`, the 503 setup page and the
404, so its behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`serveStaticAsset(ctx, component, request, options?)` serves an uploaded file
from an app-owned HTTP action and returns null when no file matches, so the app
can write its own routing order: server rendering, prerendered pages next to an
SPA shell, canonical redirects. Found files get the same response as
`registerStaticRoutes`.

The lookup is exact by default (`/` is not mapped to `/index.html` and
`spaFallback` defaults to false), so the SPA shell never answers for a route
the app handles. `path` looks up a different file, such as the shell.

Also export `decodeRequestPath` so app path checks see the same decoded path.

`registerStaticRoutes` is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Publishing a deployment used to delete the previous deployment's files right
away, so a page that was already open could no longer load its lazy-loaded
scripts or styles. Replaced storage files now move to a `retiredAssets` table
for seven days. A request for a missing file with an extension, except HTML,
gets the newest replaced copy. Old HTML never comes back, and paths without an
extension keep the current SPA fallback. Later uploads delete expired files,
and every cleanup path skips files that have not expired.

Legacy CDN blobs are not retained.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add example-ssr/, which renders TanStack Start pages inside a Convex HTTP
action. One catch-all route serves uploaded files with `serveStaticAsset`,
returns 404 for missing `/assets/` files, and renders every other path. The
page reads a click counter through Convex's TanStack Query integration: the
count and the render time are in the server's HTML, and the count stays live
after hydration.

`npm run dev` keeps a dev deployment in sync: `convex dev --start` pushes the
backend, and on each change the example rebuilds its bundles and uploads the
browser files.

The example is an npm workspace, so a root `npm install` installs it and links
it to this package. It needs its own package.json because the Convex CLI reads
package.json and convex.json from the directory it runs in. Root typecheck and
lint include it, and CI builds it before running them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove the seven-day retention implementation, tests, and documentation from the custom routing PR. Keep the preview upload option, serveStaticAsset API, and SSR example together.
chokidar-cli starts a new build and upload for every change without
waiting for the previous one. Two builds could write dist at once, and an
older upload could publish last and remove scripts that the newer server
bundle requests. The watcher script queues one more run instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nicu-chiciuc
nicu-chiciuc merged commit 2f4955c into main Oct 11, 2026
4 checks passed
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