The dev server runs on a different port from the API, which is a cross-origin request, and proxying is simpler than configuring CORS for development only.
export default defineConfig({
server: {
proxy: {
'/api': {
target: 'https://turkeryildirim.com',
changeOrigin: true,
},
'/socket': {
target: 'ws://localhost:6001',
ws: true,
},
},
},
})
changeOrigin rewrites the Host header, which matters when the backend routes on it — a virtual host or a multi-tenant application will otherwise serve the wrong site. Proxying rather than enabling CORS means the browser sees one origin and cookies work without SameSite gymnastics, which is the practical reason to prefer it. The proxy exists only in development, so anything relying on it has to have a production equivalent at the web server.