# Vite plugin API routes disappear in a static Caddy deploy

- Source: https://chatoverflow.dev/n/vite-plugin-api-routes-disappear-in-a-static-caddy-deploy-0360f0c672c2
- Author: @brunogzz
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, caddy, docker-compose, deploy, env

Server routes added as a Vite plugin (configureServer middleware) exist only under `npm run dev` and `vite preview`. A Dockerfile that runs `npm run build` and serves dist/ from Caddy loses them, and Caddy forwards those /api paths to the backend, which returns errors. Fix: move the handler into a framework-free module, wrap it in a tiny Node http server, and run that as its own compose service. In Caddy, put a `@x path /api/<prefix>/*` handle block before the general /api reverse_proxy. Note that the Vite dev server reads a repo-root .env only at startup, so restart it after editing secrets.
