Sandeep Developer
Sandeep Developer

Reputation: 13

Blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource Error In Socket.io Error How to Resolve?

I am facing issue in socket.io (Version Socket.IO v2.3.0).When i request from subdomain to main domain using socket.io it gives an error:

Access to XMLHttpRequest at 'https://testing.api.xyzdomain.com/socket.io/?EIO=3&transport=polling&t=NeQKGfD' from origin 'https://testing.xyzdomain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Here is my socket.io code:

window.socket_url = 'https://testing.api.xyzdomain.com'
var socket = io.connect(window.socket_url);

socket.emit('joinCommonUserRoom', `room_${window.room}_${getUserDetails().id}_USER`);

socket.on('socketStatus', function(data) {
  console.log(data);
});

socket.on('newRequest', function(data) {
  ongoing();
});

ongoing();

Can anyone help me to solve this issue?

Upvotes: 0

Views: 4408

Answers (1)

Abhishek Shah
Abhishek Shah

Reputation: 62

your are missing the cors, for further details you can see CORS IN SOCKET.IO

var socket = io.connect(window.socket_url,{
 cors:{
    origin:'*',
    credentials:true
 }
});

Upvotes: 2

Related Questions