websocketnestjsinsomnia

How can I test a NestJS WebSocket Server with Insomnia? Error: "socket hang up"


I'm trying to test my WebSocket Server. I want to connect to the server and verify If I can log an access token in the terminal. The Insomnia:

enter image description here

My Nest implementation:

@WebSocketGateway(0, {
  cors: {
    origin: '*',
  },
})
export class WorkGateway {
  @WebSocketServer()
  private server: Server;
  private logger: Logger = new Logger('WorkSocket');

  constructor(private readonly authService: AuthService) {}

  handleConnection(client: Socket) {
    const id = this.authService.verify({
      accessToken: client.handshake.headers.authorization,
    });

    console.log(id);
  }
}

From the React client, I'm able to connect, but not from Insomnia.


Solution

  • There is no support for socket io on Insomnia at current time. Go for Postman which support it since 2021.