Invalid namespace in production #4492
-
Hi everyone, I'm trying to access my socket.io server from a next.js frontend. when i run curl 'url-of-my-server' it respond properly but i get this message in the network and can't communicate with it. Everything runs in a nginx server in my VPS. Here's the way i've setup everything CLIENT import io, { Socket } from 'socket.io-client';
const ENDPOINT = process.env.SOCKET_URL || 'http://localhost:4001';
const socket = io(ENDPOINT, {
transports: ['websocket'],
autoConnect: false,
});
export { socket }; SERVER import http from 'http';
const app_socket = express();
const socketServer = http.createServer(app_socket);
const io = require('socket.io')(socketServer, {
cors: {
origin: process.env.FRONTEND_URL || 'http://localhost:3000',
methods: ['GET', 'POST'],
credentials: true,
},
});
socketServer.listen(SOCKET_SERVER_PORT, () => log.info(`Websocket server running on port ${process.env.SOCKET_SERVER_PORT}`)); Frontend runs on https://www.my-domain.com and socket server on https://www.my-domain.com/socket (as set in nginx config) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi! The screenshot suggests you are trying to reach the Are you looking for the const socket = io(ENDPOINT, {
path: "/socket",
transports: ['websocket'],
autoConnect: false,
}); |
Beta Was this translation helpful? Give feedback.
Hi! The screenshot suggests you are trying to reach the
/socket
namespace, which does not exist on the server.Are you looking for the
path
option instead?Reference: https://socket.io/docs/v4/client-options/#path