Skip to content

HMR: Websocket host handling breaks with proxy/custom domains #3503

@maximepvrt

Description

@maximepvrt

Environment

  • Operating System: Darwin
  • Node Version: v20.19.2
  • Nuxt Version: 4.0.2
  • CLI Version: 3.27.0
  • Nitro Version: 2.12.4
  • Package Manager: pnpm@10.11.1
  • Builder: -
  • User Config: compatibilityDate, sourcemap, devtools, experimental, modules, css, ui, runtimeConfig, $production, colorMode, site, plausible, $development, vite, routeRules, nitro, mdc, content, hooks, sentry
  • Runtime Modules: @nuxt/ui-pro@3.3.0, @nuxtjs/seo@3.1.0, @nuxt/content@3.6.3, @nuxt/image@1.10.0, @nuxt/scripts@0.11.10, @sentry/nuxt/module@9.42.1, @nuxtjs/plausible@1.2.0, @vueuse/nuxt@13.6.0
  • Build Modules: -

Version

v3.6.3

Reproduction

x

Description

Since the changes introduced in #3344, the websocket used by Nuxt Content now takes the current browser domain instead of the value defined in the watch option.

Nuxt Content uses its own websocket for HMR (usually on port 4000) and tries to connect using the browser’s current host + :4000.


Concrete case

  • Context: using a proxy for a custom domain (in my case Laravel Valet

  • Proxy:

    https://asso.benevolt.test => http://localhost:3000
    
  • Nuxt config to allow the domain:

    vite: {
      server: {
        allowedHosts: ['asso.benevolt.test']
      }
    }
  • Result:

    • Vite's websocket connects fine

    • But Nuxt Content’s websocket tries to connect to:

      wss://asso.benevolt.test:4000/ws
      

      → Console error:

      websocket.js:63 WebSocket connection to 'wss://asso.benevolt.test:4000/ws' failed:
      

Problems

  1. The websocket now automatically uses the browser’s current host (here asso.benevolt.test) instead of the configured value from watch.
  2. When using a custom domain over HTTPS, there should be an option to force the wss:// protocol so the websocket connection works.

Suggestions for improvement

  1. Add a configuration option in Nuxt Content to:

    • Define a custom host for the HMR websocket
    • Force HTTPS/WSS if needed
  2. Long-term consideration:

    • Use Vite’s websocket for HMR instead of having a second websocket on a separate port.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions