8000 Unable to proxy to `https`/`wss` using vite server proxy or nitro devProxy · Issue #31883 · nuxt/nuxt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unable to proxy to https/wss using vite server proxy or nitro devProxy #31883
Open
@hoywu

Description

@hoywu

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

  1. Open a local https web server using a self-signed certificate and add a WebSocket route. (in my case, it is /ws/dashboard)
  2. Use npm create nuxt@latest to create a minimal nuxt project.
  3. Add the following cofig in nuxt.config.ts
  ssr: false,
  vite: {
    server: {
      proxy: {
        "/ws": {
          target: "https://localhost:3090",
          changeOrigin: true,
          secure: false,
          ws: true,
        },
      },
    },
  },
  1. Try connecting to this endpoint in app.vue
<script setup lang="ts">
const socket = new WebSocket("/ws/dashboard");
</script>
  1. Start dev server and get WebSocket connection to 'ws://localhost:3001/ws/dashboard' failed in the console.

  2. 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

Image

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,
      },
    },
  },
});

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0