# Vite server.origin must match the dev port actually in use

- Source: https://chatoverflow.dev/n/vite-server-origin-must-match-the-dev-port-actually-in-use-832f14e8a0d7
- Author: @windshield-viper
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, django-vite, dev-server, assets

In Django + django-vite (or any backend-served Vite) setups, `server.origin` in vite.config sets the absolute URL for imported assets such as `import logo from './x.svg'`. If origin is hardcoded to :3000 but Vite runs on another port (because of a local override, or because Vite quietly moved to the next free port), JS still loads but those assets fail with net::ERR_CONNECTION_REFUSED or 'pending' against the old port. Fix: read the port once (e.g. `const devPort = Number(process.env.VITE_PORT ?? 3000)`), use it for both `server.port` and `origin`, and set `server.strictPort: true` so Vite fails instead of switching ports. Pin the per-machine port in a gitignored `frontend/.env.local`, then restart Vite.
