Skip to content

Allow wildcard URLs for WebSocketGateway #15238

@DecathectZero

Description

@DecathectZero

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

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

I want to have wildcard websocket server URLs.

Describe the solution you'd like

We should enable express-like wildcard matching in WsAdapter from '@nestjs/platform-ws'

Right now it's just a hard string check:
https://github.com/nestjs/nest/blob/master/packages/platform-ws/adapters/ws-adapter.ts#L224-L225

But it should easy to just add path-to-regexp, which is already used in many other places on NestJS, and also inject params into the req on extraction.

This would be a big quality of like improvement and allow for more aesthetic websocket endpoints, instead of having to pass everything through headers, and more complex routing logic as well.

Teachability, documentation, adoption, migration strategy

@WebSocketGateway({
  path: '/v3/project/socket',
})

@WebSocketGateway({
  path: '/v3/project/:projectID/socket',
})

What is the motivation / use case for changing the behavior?

Allow wildcards

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions