Answer the question
In order to leave comments, you need to log in
How to setup socket.io for live server?
On localhost, sockets work fine, there are no problems, but on a live server there are always errors. For a couple of days I can’t fix this problem in any way, I will be very glad if there is a solution.
If you leave only polling in transports, then there are no errors, in network everything returns with the status "ok", but it still does not work.
server:
const app = require('express')();
const server = require('http').Server(app);
const io = require("socket.io")(server, {
cors: {
origin: "*",
methods: ["GET", "POST"],
transports: ['websocket', 'polling'],
credentials: true
},
allowEIO3: true,
});
const port = process.env.PORT || 3000;
server.listen(port, () => {
console.log('socket.io, port:', port);
})
public socket = io('https://bichatgo.demo-app.live', {
transports: ['websocket', 'polling']
});
public socket = io('http://localhost:3000', {
transports: ['websocket', 'polling']
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question