This example demonstrates how to use the @convex-dev/static-hosting component to host a React/Vite app directly on Convex.
From the root of the repository:
# Install dependencies and start dev server
npm install
npm run devThis starts:
- The Convex backend development server
- The Vite frontend development server
- A file watcher for rebuilding the component
Once you have a Convex deployment, you can deploy your static files:
# Build the example app and upload to Convex
cd example
CONVEX_URL=https://your-deployment.convex.cloud npx tsx scripts/upload-static.tsYour app will then be available at https://your-deployment.convex.site.
convex/convex.config.ts- Imports and uses the static hosting componentconvex/staticHosting.ts- Exposes upload API functionsconvex/http.ts- Registers static file serving routesscripts/upload-static.ts- Script to upload built files to Convexsrc/- Example React application
- The component stores static files in Convex file storage
- HTTP routes serve files with proper Content-Type and caching headers
- SPA fallback ensures client-side routing works correctly
- Each deployment gets a unique ID for atomic updates and garbage collection