You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Insomnia测试NestJS WebSocket服务?遇“socket hang up”错误

NestJS WebSocket服务Insomnia连接报错排查

我正在测试自己开发的NestJS WebSocket服务,目标是通过Insomnia连接服务,验证终端是否能正常打印访问令牌。目前React客户端可以正常连接该服务,但使用Insomnia连接时,会出现“socket hang up”错误。

我的NestJS WebSocket网关实现代码如下:

@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);
  }
}

Insomnia的配置截图:
Insomnia WebSocket配置截图

内容的提问来源于stack exchange,提问作者Samuel A. Souza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 22:59:50