nest icon indicating copy to clipboard operation
nest copied to clipboard

Allow wildcard URLs for WebSocketGateway

Open DecathectZero opened this issue 5 months ago • 0 comments
trafficstars

Is there an existing issue that is already proposing this?

  • [x] 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

DecathectZero avatar Jun 05 '25 20:06 DecathectZero