I want my Gateway to be able to receive connections from any path as I'm going to receive user id as parameter. I'm using the ws module.
Example:
ws://localhost:3000/12345
another example:
ws://localhost:3000/54321
I put @WebSocketGateway({ path: '*' }) but it doesn't work. Here is my Gateway:
@WebSocketGateway({ path: '*' })
export class CacheGateway implements OnGatewayConnection {
private readonly logger: Logger = new Logger(CacheGateway.name);
private readonly clients: { [key: string]: WebSocket } = {};
public handleConnection(@ConnectedSocket() client: WebSocket): void {
const userID = client.url?.slice(1);
if (userID) {
this.clients[userID] = client;
this.logger.log(
`User Connected: ${userID}. At: ${new Date().toISOString()}`,
);
} else {
this.logger.log('Anonymous user connected');
}
}
}