WebSocketGateway
To implement your first module using the Nest.js web socket, you will have to use the @WebSocketGateway
decorator. This decorator can take an argument as an object to provide a way to configure how to use the adapter.
The implementation of the arguments respect the interface GatewayMetadata
, allowing you to provide:
port
, which must be use by the adapternamespace
, which belongs to the handlersmiddlewares
that have to be applied on the gateway before accessing the handlers
All the parameters are optional.
To use it, you have to create you first gateway class, so imagine a UserGateway
:
@
WebSocketGateway
({
middlewares
:
[
AuthenticationGatewayMiddleware
]
})
export
class
UserGateway
{
/*....*/
}
By default, without any parameters, the socket will use the same port as your express server (generally 3000
). As you can see, in the previous example we used a @WebSocketGateway
, which uses the default port 3000
without namespace and with one middleware that we will see...