Skip to content

[feature] add a way to register middlewares for all namespaces #3851

@darrachequesne

Description

@darrachequesne

Is your feature request related to a problem? Please describe.

Since Socket.IO v3, it is not mandatory anymore for the client to connect to the main namespace.

Registering a global middleware which applies to all namespace is thus a bit messier:

const of = io.of;
io.of = (...args) => {
  const nsp = of.call(io, ...args);
  nsp.use(yourMiddleware);
  return nsp;
}

Describe the solution you'd like

io.<name of the method>(yourMiddleware); // register a middleware which will be attached to each namespace

Describe alternatives you've considered

Registering a global middleware is possible for dynamic namespaces:

const parentNamespace = io.of(/^\/dynamic-\d+$/);

parentNamespace.use(yourMiddleware); // attached to all child namespaces

Additional context

Related: #3842

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