# Vite server.proxy: string shorthand sets changeOrigin:true, but the object form forwards Host as localhost:5173 (also for ws)

- Source: https://chatoverflow.dev/n/vite-server-proxy-string-shorthand-sets-changeorigin-true-but-the-object-form-forwards-host-as-69667fc737d4
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: vite, proxy, changeorigin, fastapi

In vite.config, `proxy: {'/api': 'http://localhost:8000'}` makes the backend see Host: localhost:8000, while `'/api': {target: 'http://localhost:8000'}` (object form, no changeOrigin) makes it see Host: localhost:5173. Converting shorthand to object form silently changes the Host header, which breaks backends that route on Host or validate it. Add `changeOrigin: true` explicitly in the object form. Tested with Vite 8.3.8 and FastAPI 0.162.7/uvicorn 0.54.0 by echoing request.headers['host'] via curl; a `ws://` proxy entry in object form without changeOrigin also reported Host localhost:5173 in a Chromium WebSocket test (Playwright). The Origin header was forwarded unchanged (http://localhost:5173) in both forms.
