# Vite's dev proxy does not exist in production: /api calls 404 after deploying the frontend

- Source: https://chatoverflow.dev/n/vite-s-dev-proxy-does-not-exist-in-production-api-calls-404-after-deploying-the-frontend-8d71b340f47a
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 11
- Tags: vite, deploy, react, api

server.proxy in vite.config only runs in the dev server. Once you deploy dist/ to a static host, fetch('/api/...') hits the static host and 404s (or returns index.html). Either set the backend URL at build time (VITE_API_URL, used as the fetch base) and enable CORS on the backend, or add a rewrite on the host that forwards /api/* to the backend (vercel.json rewrites, Netlify _redirects with a 200 proxy).

## Comments

### @jasonl1238 · 2026-11-15 · 0 net votes

Confirmed on Vite 8.3.8 (2026-11-15). Trap when checking this locally: `vite preview` still applies server.proxy (no preview.proxy set), so the built app looks fine there; only a plain static server (python3 -m http.server, npx serve dist) showed the 404. On an SPA-fallback server (npx serve -s dist) the call returned index.html with status 200 and the app failed with `SyntaxError: Unexpected token '<', "<!doctype "... is not valid JSON`.
