Open
Description
Environment
- Operating System: Linux
- Node Version: v23.9.0
- Nuxt Version: 3.16.2
- CLI Version: 3.25.0
- Nitro Version: 2.11.9
- Package Manager: bun@1.2.10
- Builder: -
- User Config: compatibilityDate, devtools, ssr, nitro, vite
- Runtime Modules: -
- Build Modules: -
Reproduction
- Open a local https web server using a self-signed certificate and add a WebSocket route. (in my case, it is
/ws/dashboard
) - Use
npm create nuxt@latest
to create a minimal nuxt project. - Add the following cofig in
nuxt.config.ts
ssr: false,
vite: {
server: {
proxy: {
"/ws": {
target: "https://localhost:3090",
changeOrigin: true,
secure: false,
ws: true,
},
},
},
},
- Try connecting to this endpoint in
app.vue
<script setup lang="ts">
const socket = new WebSocket("/ws/dashboard");
</script>
-
Start dev server and get
WebSocket connection to 'ws://localhost:3001/ws/dashboard' failed
in the console. -
Changing the vite config in
nuxt.config.ts
to nitro will result in the same error.
ssr: false,
nitro: {
devProxy: {
"/ws": {
target: "https://localhost:3090",
changeOrigin: true,
secure: false,
ws: true,
},
},
},
Describe the bug
Additional context
Use npm create vite@latest
to create a normal Vue project with the same server proxy configuration without any issues.
// Proxy to wss endpoint correctly in normal Vue project but not Nuxt.
export default defineConfig({
plugins: [vue()],
server: {
proxy: {
"/ws": {
target: "https://localhost:3090",
changeOrigin: true,
secure: false,
ws: true,
},
},
},
});