---
title: "Deploy React & Vite"
description: "Build and deploy a React, Vite, Vue, or Svelte single-page application to Hosted EZ with SPA fallback, immutable asset caching, and automated GitHub Actions deploys."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.hostedez.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy React & Vite

Single-page applications built with **Vite** (React, Vue, Svelte, Preact, Solid) compile to a static `dist/` folder with content-hashed JavaScript and CSS assets under `dist/assets/`. Hosted EZ's **Static Site** runtime serves these bundles directly from nginx with built-in SPA fallback routing.

## 1. Create a Static Site with SPA fallback

1. **Create the site**

   In [app.hostedez.com](https://app.hostedez.com/dashboard?tab=sites&new=1), click **Sites → New site** and choose **Static Site**.
2. **Enable SPA fallback**

   In Step 2, enter your site name and check **SPA fallback**. Leave **Clean URLs** unchecked for standard client-side SPAs.

   With **SPA fallback** enabled, nginx uses `try_files $uri $uri/ /index.html;` so deep links like `/projects/42/settings` load your app shell instead of returning `404`, while real missing static assets (`.js`, `.css`, images) still return `404` cleanly.

## 2. Verify your Vite configuration

Ensure `base` in `vite.config.ts` matches the root path `/` (Vite's default):

```ts title="vite.config.ts"
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
  base: "/",
  build: {
    outDir: "dist",
  },
});
```

If you use React Router, Vue Router, or TanStack Router, use standard browser history (`createBrowserRouter` / `createWebHistory`)—hash routing (`/#/`) is not needed once SPA fallback is enabled.

## 3. Build and deploy

### Dashboard Archive Deploy (1-click rollback)

Build locally and zip `dist/`:

```bash
npm ci
npm run build
zip -r dist.zip dist/
```

Open your site's **Deployments** tab, drag and drop `dist.zip`, add a release note (for example, `v1.4.0 — checkout redesign`), and click **Deploy**. Hosted EZ automatically strips the top-level `dist/` folder, swaps `public_html` atomically, and keeps the last 10 releases for instant rollback.
### GitHub Actions (SFTP)

Add your deployment SSH public key in **Site → SFTP → Add SSH key** and store the matching private key in GitHub repository secrets as `HOSTEDEZ_SFTP_KEY`, along with `HOSTEDEZ_SFTP_USER` (`sftp_<siteSlug>`).

```yaml title=".github/workflows/deploy.yml"
name: Deploy Vite app to Hosted EZ

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm

      - run: npm ci
      - run: npm run build

      - name: Install lftp
        run: sudo apt-get update && sudo apt-get install -y lftp

      - name: Upload dist/ over SFTP
        env:
          SFTP_USER: ${{ secrets.HOSTEDEZ_SFTP_USER }}
          SFTP_KEY: ${{ secrets.HOSTEDEZ_SFTP_KEY }}
        run: |
          install -m 600 /dev/null "$RUNNER_TEMP/deploy_key"
          printf '%s\n' "$SFTP_KEY" > "$RUNNER_TEMP/deploy_key"
          lftp -u "$SFTP_USER," sftp://sftp.hostedez.com:22 <<EOF
          set sftp:connect-program "ssh -a -x -i $RUNNER_TEMP/deploy_key -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new"
          set net:max-retries 3
          mirror -R --delete --verbose --parallel=4 dist/ public_html/
          quit
          EOF
```

See [SFTP & GitHub Actions CI/CD](/deploy/sftp-and-github-actions) for host-key pinning and multi-environment setups.

## 4. Recommended headers for Vite SPAs

Open **Site → Routing → Static Delivery** and add two Custom Response Header rules:

| Path Prefix | Header | Value | Why |
| --- | --- | --- | --- |
| `/` | `Cache-Control` | `no-cache, must-revalidate` | Ensures `index.html` always fetches the newest asset manifest after each deploy |
| `/` | `X-Frame-Options` | `DENY` | Blocks clickjacking embeds |
| `/` | `Referrer-Policy` | `strict-origin-when-cross-origin` | Limits referrer leakage to external origins |
| `/assets` | `Cache-Control` | `public, max-age=31536000, immutable` | Caches Vite's content-hashed JS/CSS/font bundles for 1 year at browsers and CDN |

> **Environment variables in Vite**
>
> Vite embeds `VITE_*` environment variables at **build time**, not runtime. Never place private API secrets in `VITE_*` variables—they are bundled into public JavaScript files served to browsers.

## Troubleshooting

- **Blank page after deploy with `Failed to load module script`**: Check that `base` is `/` in `vite.config.ts` and that `index.html` sits directly at `public_html/index.html` (check the **File Manager** tab).
- **404 on browser refresh on a nested route**: Verify **SPA fallback** is enabled under **Site → Routing → Static Delivery**.
- **Stale bundle after deploying**: If you set a custom `Cache-Control` on `/`, keep `no-cache, must-revalidate` on `/` and only put `immutable` on `/assets`. If **Global Edge CDN** is active and you deployed via SFTP, click **Purge cache** in the **Performance** tab.

Source: https://docs.hostedez.com/deploy/react-vite/index.mdx
