# Deploy Vite & static SPAs on forkrail

> Zero Lambda functions, zero cold starts. forkrail builds `dist/`, stores assets by content hash in S3 across your active regions, and serves them directly from the regional Rust routers.

- Framework: Vite
- Category: Websites & full-stack
- Status: Production ready
- Adapter / Preset: None (auto-detects dist/)
- Runtime: Static S3 (no Lambda · optional api/ functions)
- Detection: package.json (vite)
- Memory: None (static delivery only)
- URL: https://www.forkrail.com/frameworks/vite

## Capabilities

| Capability | Support | Details |
| --- | --- | --- |
| Zero-Lambda serving | Supported | Served from router memory cache and regional S3 buckets |
| SPA fallback rewrites | Supported | Standard vercel.json catch-all rewrite to /index.html |
| Functions in api/ | Supported | Add Node, Python, Go, or Rust endpoints beside your SPA |
| Routing middleware | Supported | Optional root middleware.ts for auth, geo, or A/B routing |

## 1. Configure SPA routing (optional)

forkrail runs your `build` script and deploys `dist/` automatically (or any custom `outputDirectory` in `vercel.json`). For client-side routed single-page apps (React, Vue, Solid, Preact), add a catch-all rewrite to `/index.html`, just like on Vercel:

**vercel.json**

```json
{
  "rewrites": [
    { "source": "/(.*)", "destination": "/index.html" }
  ],
  "headers": [
    {
      "source": "/assets/(.*)",
      "headers": [
        { "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
      ]
    }
  ]
}
```

## 2. Deploy & set VITE_* build variables

Any environment variable added to the project is available during `vite build` (so `import.meta.env.VITE_*` embeds cleanly per environment — Preview vs Production).

**Set build env vars and deploy**

```bash
printf 'https://api.acme.dev' | forkrail env add web-spa VITE_API_URL --target production
forkrail deploy --prod
```

## 3. Add backend endpoints in api/

Need a few backend endpoints without standing up a separate service? Drop files in `api/` (for example `api/contact.ts` or `api/checkout.ts`) and forkrail serves `/api/*` alongside your Vite static files. See [Functions in api/](https://www.forkrail.com/docs/functions).

## Related documentation

- [Redirects, rewrites & headers](https://www.forkrail.com/docs/routing.md)
- [Functions in api/](https://www.forkrail.com/docs/functions.md)
- [Custom domains](https://www.forkrail.com/docs/domains.md)
