You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Hi! I have a socket server that is not of the same origin as my website. Some of my users are unable to connect and always return the XHR poll error upon connecting (status code 0). We've also tried other browsers but still the same error.
I found out also that the user's browser is unable to perform a GET/POST request on my socket server (status code 0).
It's kinda weird that most of the users are connected and able to request from the server.
I am unable to replicate it on my end. Is this something on their ISP or browser settings?
Server
express version: ^4.17.1
cors: ^2.8.5
Socket.IO server version: ^4.0.1
constpath=require('path');consthttp=require('http');constexpress=require('express');constcors=require('cors');constsocketio=require('socket.io');constcreateNotificationObject=require('./utils/notifications');constwhitelist=[...];varcorsOptions={origin: function(origin,callback){if(whitelist.indexOf(origin)!==-1||!origin){callback(null,true)}else{callback(newError('Not allowed by CORS'))}}}varonlineUsers={};constapp=express();app.use(express.json({limit:'1mb'}));app.all('*',cors(corsOptions),function(req,res,next){next();});constserver=http.createServer(app);constio=socketio(server,{allowEIO3: true,cors: {origin: whitelist,methods: ["GET","POST"],credentials: true}});app.post('/emit-notification',function(req,res){console.log(req.body);io.emit('notification',createNotificationObject(req.body));res.json({statusText: 'success',status: 200});});//Run when client connectsio.on('connection',socket=>{console.log(`Successfully connected`);socket.on('online',function(data){console.log(`User ${(userinfo&&userinfo.Id)||''} connected`);});});constPORT=process.env.PORT||3000;server.listen(PORT,()=>console.log(`Server running on port ${PORT}`));
Socket.IO client version: ^4.1.3
Client
constsocketServer='...';varsocket=io(socketServer);socket.on('connect',()=>{console.log('SOCKET SERVER CONNECTED: ',socket.connected);});socket.on('notification',payload=>{console.log('NEW NOTIFICATION',payload);});
Expected behavior
Should connect to the socket server
Platform:
Browser: Chrome 94.0.4606.81
OS: Windows 10
The text was updated successfully, but these errors were encountered:
Describe the bug
Hi! I have a socket server that is not of the same origin as my website. Some of my users are unable to connect and always return the XHR poll error upon connecting (status code 0). We've also tried other browsers but still the same error.
I found out also that the user's browser is unable to perform a GET/POST request on my socket server (status code 0).
It's kinda weird that most of the users are connected and able to request from the server.
I am unable to replicate it on my end. Is this something on their ISP or browser settings?
Server
express version:
^4.17.1
cors:
^2.8.5
Socket.IO server version:
^4.0.1
Socket.IO client version:
^4.1.3
Client
Expected behavior
Should connect to the socket server
Platform:
The text was updated successfully, but these errors were encountered: