I have a developer environment where there is an Nginx dev server and some requests are routed to my local machine and some a routed to the staging environment in the internet.
I'm using vitejs.dev and everything works except for the Websocket connection of Vite's Hot Module Replacement (HMR).
vite.config.ts
export default defineConfig({
server: {
host: true,
port: 3300,
hmr: {
path: '/__vite_hmr',
},
},
})
nginx config
location ~* /__vite_hmr {
proxy_pass "http://cr-frontend:3300";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
I can successfully proxy other requests to http://cr-frontend:3300 but not Vite's HMR. This is what I get:
client.ts:28 WebSocket connection to 'wss://url.xyz:3300/__vite_hmr' failed:
Any idea?