Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io not sending cookies in the handshake causing the request to stall

Let me explain my setup. I have multiple domain names that are all CNAME records for a main domain name, such as example.com.

example.com -> serverIP

company1.example.com -> example.com

company2.example.com -> example.com

I'm basically developing white labeled versions of our software, where the software simply detects the referrer and knows which logos and stylesheet assets to load.

So that is all well and good, however when socket.io tries to handshake to it's url that looks something like http://company1.example.com/socket.io/1/?key=123456, the request hangs in a pending state upon signing into the app. On the main domain, example.com, everything goes through just fine. The dfference is that the main domain sends in a cookie to the socket.io handshake URL whereas the company subdomains do not.

Does anyone have any ideas on how to fix this? It doesn't appear to even be reaching the server and after a few minutes the pending request returns that it could not be completed.

like image 676
jrthib Avatar asked Oct 28 '25 18:10

jrthib


1 Answers

I had a similar problem and found that the issue was from the JS Client I was using. I solved this by adding withCredentials: true to my connection config.

Here is how it looks

import io from "socket.io-client";

const connectionObject  = {
  ...,
  withCredentials: true,
};
socket = io("http://127.0.0.1:5000" || "", connectionObject);

This added Cookies to calls to my Socket Server.

like image 57
Chidiebere Avatar answered Oct 31 '25 08:10

Chidiebere



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!