Questions tagged [nestjs-gateways]
42 questions
10
votes
3 answers
How to access websocket from controller or another component/services?
I have a REST API, I want to send event to the client via websocket.
How to inject websocket instance in controller or another component?

A. Arif
- 427
- 1
- 5
- 8
9
votes
4 answers
Can we use server sent events in nestjs without using interval?
I'm creating few microservices using nestjs.
For instance I have x, y & z services all interconnected by grpc but I want service x to send updates to a webapp on a particular entity change so I have considered server-sent-events [open to any other…

Nikhil.Nixel
- 555
- 2
- 11
- 25
7
votes
1 answer
nestjs + socket.io serving websockets from microservice at nested path instead of the root of the host always returns 404 Not Found
I'm using the socket.io implementation with nestjs. My overall in-production architecture is relying on a load balancer to route requests on paths to microservice containers.
One of them contains a websocket that interacts with user data and is…

SebastianG
- 8,563
- 8
- 47
- 111
6
votes
1 answer
NestJS Websocket Gateway: using namespaces with the WS adapter
I am working on implementing a Websocket gateway in NestJS 7, as shown in the docs. I use the WS adapter.
const app = await NestFactory.create(ApplicationModule);
app.useWebSocketAdapter(new WsAdapter(app));
The problem I have is that the gateway…

BeetleJuice
- 39,516
- 19
- 105
- 165
4
votes
2 answers
Nestjs websocket gateway, how to parse signed cookies from handshake for guard authorization?
My guard contains the following code:
let client: Socket = context.switchToWs().getClient();
const sessionCookie = client.handshake.headers.cookie
.split('; ')
.find((cookie: string) => cookie.startsWith('session'))
…

SebastianG
- 8,563
- 8
- 47
- 111
3
votes
1 answer
How to get nestjs websocket exception error in client side using react?
I am try to create a realtime project for practice. I use nestjs for backend and react for frontend. Here in nestjs I am suing websocket.
In nestjs I write this code
@SubscribeMessage("createMessage")
handleCreate(
@MessageBody() messageInput:…

Jannat
- 65
- 5
3
votes
0 answers
How to use guards with NestJs gateway(web sockets)?
In my NestJS API, I'm JWT token, stored in a cookie to authenticate my users.
The user will have to call my login controller:
@UseGuards(LocalAuthenticationGuard)
@Post('login')
async logIn(@Req() request: RequestWithUser) {
const { user }…

J4N
- 19,480
- 39
- 187
- 340
3
votes
1 answer
How to implement database first approach in Nest JS
I have three schemas(User, Account, Contact) these three schemas used to created a model and generate the migration files also Next, this migration file migrate the PostgreSQL Database this part successfully completed using Nest JS.
Next, Manually I…

Hariprasath Vengatachalam
- 155
- 6
- 18
3
votes
3 answers
NestJs transform GRPC exception to HTTP exception
I have a HTTP server that connects to a gateway over GRPC. the gateway also connects to other . GRPC microservices. the flow looks like this:
Client -> HttpServer -> GRPC server (gateway) -> GRPC microservice server X
The way i handle errors…

Jay Povey
- 539
- 2
- 6
- 15
2
votes
0 answers
How can understand error occured in backend using socket client in react?
My question is about socket io using nestjs and react. Here I am using nestjs for backend implementation and react for frontend implementation.
In Backend- I use nestjs webscoket with validation pipe. I also create a simple SubscribeMessage like…

Jannat
- 65
- 5
2
votes
2 answers
How to handle RpcException in NestJS
I am trying to build a NestJS backend with multiple microservices and one REST API as a Gateway which communicates with the microservices. For communication between the Gateway and Microservices I am using gRPC.
Simple communication is already…

davidrui6
- 31
- 1
- 4
2
votes
1 answer
Socket.io client is getting disconnected just after connection in NestJS
I'm trying to create chat with nestjs, and it is problem with its @SubscribeMessage(),
implementation with connection is working, but when I try to listen the emits from frontend and console the data in nestjs, it not works
import { Server, Socket…

Vahan
- 28
- 3
- 11
2
votes
1 answer
Nestjs socket from exception filter context is defined even though exception comes from http request and there's no sockets within app?
I'm trying to use a "bad input exception filter" to catch errors and return them to the client. I have both websockets and http endpoints throughout my monorepo, on one application I have both.
The issue I'm having, I don't want to use two separate…

SebastianG
- 8,563
- 8
- 47
- 111
2
votes
1 answer
Nestjs wss handleConnection(socket) socket.handshake is undefined and cannot access headers to authenticate
I have a Nestjs gateway where I'm trying to run authorization logic depending on values from the headers but wherever I'm trying to access the handshake it always returns 'undefined'
I'm also trying this over SSL which might be making a…

SebastianG
- 8,563
- 8
- 47
- 111
2
votes
1 answer
Nestjs how to use http request and Websocket at the same time
I have a controller in Nestjs that handles an HTTP request. There is an IoT device that communicates with the server and sends the latest changes to the server with a post request. At the same time, there is a mobile application that should receive…

Vahid Najafi
- 4,654
- 11
- 43
- 88