LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-12-2022, 06:46 AM   #1
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Rep: Reputation: 34
[nodejs v14][socket.io v4] : xhr poll error & CORS issue


Hello

I have node+socket.io :
Code:
[root@socketio]# node -v
v14.18.3
[root@socketio]# npm list socket.io
/var/socketio
└── socket.io@4.4.1
Socket.io server config :
Code:
var fs = require('fs');
var options = {
  key: fs.readFileSync('/etc/letsencrypt/live/my.domain.tld/privkey.pem'),
  cert: fs.readFileSync('/etc/letsencrypt/live/my.domain.tld/fullchain.pem')
};
var cors = require('cors');
var server = require('https').createServer(options)
var io = require('socket.io')(server, { cors: { origin: true } });
server.listen(port, function(){
    console.log('listening on *: '+ port + "\n");
});
On my socket.io-client server I have :
Code:
var io = require('socket.io-client');
var wsServer='https://my.domain.tld:4123';
// Connect to our node/websockets server
var socket = io.connect(wsServer, {
    reconnection: true,
    reconnectionDelay: 1000,
    reconnectionDelayMax : 5000,
    reconnectionAttempts: 3
});
I get output :
Code:
connect_error due to xhr poll error
On my Chrome browser I have :
Code:
// Connect to our websocket-server
var socket = io.connect('https://my.domain.tld:4123');
Here I get in my browser :
Code:
Access to XMLHttpRequest at 'https://my.domain.tld:4123/socket.io/?EIO=3&transport=polling&t=NvEIxIV' from origin 'https://mydomain.tld' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
When adding more CORS (as I read on stackOverflow) :
Code:
{ cors: { origin: true, credentials: true } }
I get :
Code:
GET https://my.domain.tld:4123/socket.io/?EIO=3&transport=polling&t=NvEJVnb 400 (Bad Request)
Again I add more CORS (as I read on the internet) :
Code:
cors: { origin: true, credentials: true, methods: ["GET", "POST"], transports: ['websocket', 'polling'] } }
Still I get in my Chrome browser :
Code:
GET https://my.domain.tld:4123/socket.io/?EIO=3&transport=polling&t=NvEJVnb 400 (Bad Request)
And on my socket.io-client server :
Code:
connect_error due to xhr poll error
So what am I missing here ??
 
Old 01-12-2022, 07:35 AM   #2
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
According to Version compatibility on https://socket.io/docs/v4/client-installation/ I need to use
Code:
allowEIO3: true
So my socketio-client server is now OK.

But in my Google browser I still get :
Quote:
Access to XMLHttpRequest at 'https://my.domain.tld:4123/socket.io/?EIO=3&transport=polling&t=NvEVqU1' from origin 'https://mydoamin.tld' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] nodejs, nodejs-dev incompatibility in Ubintu? mjbradakis Linux - Software 1 03-24-2013 11:50 PM
[SOLVED] slackware64 v14 problems with amarok - no sound, looks dead morrgp Slackware 2 09-30-2012 10:17 PM
[SOLVED] Upgraded to slackware64 v14. lost all of my e-mail morrgp Slackware 4 09-30-2012 06:53 AM
Problem with SuSE 9.2 and Fedora Cors 3 install! mikepg Linux - Software 8 04-10-2005 09:02 PM
Gotta love those ٱٱٱٱٱٱٱ&# iLLuSionZ Linux - General 5 11-18-2003 07:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration