Skip to content

Access to root server on 'listen' hook for websocket setup #101

Closed

Description

@Dodobibi

Environment



Reproduction

In a module :

nuxt.hook('listen', (server) => {
    // server is not the root server, but it's a proxified server handled by nuxi.
    // unable to do this :
    server.on('upgrade', (req, socket, head) => {
       // handle socket
       // socket.write(...) does nothing
    });
});

Describe the bug

With nuxt 3.7 :
Since nuxi create a proxy for handle only web request beetween root server and devServer, we are unable to attach websockets to the root server.
The server in listen hook is not the root server (listening on localhost:3000), but the devServer (listening on localhost:xxxxx).
Websocket must be attached on the root server for working, because proxy create by nuxi proxify only the web requests.

Additional context

No response

Logs

No response

Activity

  1. changed the title [-]Access to root server on 'listen' hool[/-] [+]Access to root server on 'listen' hook[/+] on Aug 26, 2023
  2. added
    bug
    on Aug 26, 2023
  3. changed the title [-]Access to root server on 'listen' hook[/-] [+]Access to root server on 'listen' hook for websocket setup[/+] on Aug 26, 2023
  4. transferred this issue fromnuxt/nuxton Aug 26, 2023
  5. pi0 commented on Aug 30, 2023

    @pi0
    Member

    Hi. A fix is released in v3.7.3. Check out this example for usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions