1.0.9 • Published 2 years ago

@drozd/nestjs-ws-api v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@drozd/nestjs-ws-api

NPM version

1) Turns a normal REST api into a websocket. 2) Accelerates api by 10 times due to one open ws channel. 3) Controllers also remain native swagger REST API.

Setup

npm install @drozd/nestjs-ws-api

or

yarn add @drozd/nestjs-ws-api

then inside your app.module.ts add config:

@Module({
  imports: [
    ConfigModule.forRoot(),
    WsModule.registerAsync({
      useFactory: (): IWsApiConfig => {
          return {
            validationConfig,
            async validate(socket: Socket) {
              console.log(new ExecutionContextHost([socket]));
              return HttpStatus.OK;
            },
          };
      },
    }),
  ],
})
export class AppModule {}

And more use in controllers

  @Get(':id')
  @WsAction('user')
  getUser(@Param('id', ParseIntPipe) id: number): UserDto {
    return this.appService.getUser(id);
  }

See full demo https://github.com/gustoase/nestjs-ws-api-demo

License

MIT