question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting 404 error with @nestjs/websockets

See original GitHub issue

Server :

import {
    ConnectedSocket,
    MessageBody,
    OnGatewayConnection, OnGatewayDisconnect, OnGatewayInit,
    SubscribeMessage,
    WebSocketGateway,
    WebSocketServer
} from '@nestjs/websockets';
import { Server, Socket } from 'socket.io';
import { Logger } from '@nestjs/common';

@WebSocketGateway()
export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
    @WebSocketServer()
    server: Server;

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

    @SubscribeMessage('msgToServer')
    handleMessage(client: Socket, payload: string): void {
        this.server.emit('msgToClient', payload);
    }

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

    handleDisconnect(client: Socket) {
        this.logger.log(`Client disconnected: ${client.id}`);
    }

    handleConnection(client: Socket, ...args: any[]) {
        this.logger.log(`Client connected: ${client.id}`);
    }
}

Client side:

import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
const socketConfig: SocketIoConfig = {
    url: 'http://localhost:3000',
    options: {
        path: '/'
    }
};

Error

GET http://localhost:3000/?EIO=4&transport=polling&t=NhD2AKw 404 (Not Found)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:7

github_iconTop GitHub Comments

2reactions
memeecommented, Dec 9, 2021

Guys, make sure you’re hitting your nestjs server. If you use angular you might want to configure proxy like that:

{
  "/api": {
    "target": "http://localhost:3333",
    "secure": false
  },
  "/socket.io": {
    "target": "http://localhost:3333",
    "secure": false
  }
}
0reactions
csulitcommented, Dec 12, 2022

Same error mine works in dev but not in production.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket connection failed errors after upgrade to Next.js 12
js 12, I'm getting the following error while running the app in dev mode: WebSocket connection to 'wss://app.name.dev/_next/webpack-hmr' failed:.
Read more >
Next.js default 404 page is not shown for non-existing pages
I'm creating a next.js app. And when I enter a non-existing URL, instead of seeing the default 404 page, I see this message:....
Read more >
Javascript console full of WebSocket errors with HTTP code ...
However, the problem has only been solved partially. Now the response code turned from 404 into 405 “method not allowed”. :frowning:.
Read more >
Dynamic Routes Details - Next.js
The paths that have not been generated at build time will not result in a 404 page. Instead, Next.js will serve a “fallback”...
Read more >
Socket.io client connect 404 not found on Netlify - Support
i have this problem to. i'm using nextjs and my chatbox works in local machine but when i deployed it on netlify i...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found