小编ken*_*rth的帖子

如何修复socket io中的400错误错误请求?

我有一个前端应用程序(VUE JS)

我有一个后端(Nest JS)

Vue JS 应用程序使用 vue-socket.io-extended 库通过 websockets 从后端获取数据当 Vue JS 应用程序启动时,我在浏览器中看到错误:

polling-xhr.js?d33e:229 POST http://localhost:11050/socket.io/?EIO=4&transport=polling&t=NMXgCF1 400(错误请求)

错误

我该如何解决这个错误?

我认为它没有与库连接,我只是尝试了 socket io 库,结果是一样的。

服务器正在工作,因为它发送日志并显示谁已连接:

服务器响应

服务器(Nest JS) main.ts 文件:

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors();
  await app.listen(11050);
}
bootstrap();
Run Code Online (Sandbox Code Playgroud)

应用网关:

@WebSocketGateway()
export class AppGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {


  private logger: Logger = new Logger('AppGatway');

  @SubscribeMessage('msgToServer')
  handleMessage(client: Socket, text: string): WsResponse<string> {
    return { event: 'msgToClient', data: text };
  }

  afterInit(server: Server) {
    this.logger.log('Initialised!');
  }

  handleConnection(client: Socket, …
Run Code Online (Sandbox Code Playgroud)

javascript websocket socket.io vue.js nestjs

10
推荐指数
5
解决办法
9519
查看次数

标签 统计

javascript ×1

nestjs ×1

socket.io ×1

vue.js ×1

websocket ×1