Skip to content

Node: prevent repeated serve() calls from registering duplicate upgrade handlers #205

Description

@jakub300

Describe the feature

const originalServe = server.serve;
server.serve = () => {
server.node?.server!.on("upgrade", (req, socket, head) => {
ws.handleUpgrade(
req,
socket,
head,
// @ts-expect-error (upgrade is not typed)
new NodeRequest({ req, upgrade: { socket, head } }),
);
});
return originalServe.call(server);
};

Serve in current node code (above) is adding event listeners on every serve call. Incorrect use (multiple serve calls) leads to unexpected behaviour. Repeated serve calls should either do noting or throw exception.

Additional information

  • Would you be willing to help implement this feature?

Activity

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions