nest icon indicating copy to clipboard operation
nest copied to clipboard

feat(ws): add regex path support on platform ws path

Open RavenColEvol opened this issue 1 year ago • 2 comments
trafficstars

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [ ] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • [ ] Bugfix
  • [x] Feature
  • [ ] Code style update (formatting, local variables)
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] CI related changes
  • [ ] Other... Please describe:

What is the current behavior?

Currently Websocket Adaptor only takes strict pathname as parameter but common use case like YJS works on random websocket route /ws/:room_id which makes it hard nest js to be used in those scenario. This PR will help fixing that use case.

Issue Number: N/A

What is the new behavior?

Websocket Adaptor path parameter can now take pathregex as input like ws/:room_id and it will allow request url which match that pathregex.

import { SubscribeMessage, WebSocketGateway } from '@nestjs/websockets';

@WebSocketGateway({
  path: '/ws-path/:room_id',
})
export class WsPathGatewayRegex {
  @SubscribeMessage('push')
  onPush(client, data) {
    return {
      event: 'pop',
      data,
    };
  }
}

Does this PR introduce a breaking change?

  • [ ] Yes
  • [x] No

Other information

I tried running integration test on my local system with docker up but still there were few failing tests for me. I'm new to mocha ( have use jest ) ws-gateway, rpc integration are failing for me even if I roll back my changes. I ran ws-gateway test cases individually as it was not dependent on any docker container with this command

npx mocha --watch integration/websockets/e2e/ws-gateway.spec.ts

RavenColEvol avatar Apr 05 '24 20:04 RavenColEvol

Pull Request Test Coverage Report for Build 14d10460-30b3-4248-a732-f5de2208efcf

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.123%

Totals Coverage Status
Change from base Build eacd3e56-4bed-4f5e-9bab-412a10335aab: 0.0%
Covered Lines: 6736
Relevant Lines: 7312

💛 - Coveralls

coveralls avatar Apr 05 '24 20:04 coveralls

@kamilmysliwiec do you think this PR is a valid use case?

RavenColEvol avatar Apr 17 '24 11:04 RavenColEvol