1

I am using SocketIO to create a web chat application.

When I work locally everything is fine, but when I release it to our live domain I get the following error:

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

Here is how I connect from the client to the server:

var socket = io(document.domain + ':' + supPort, {secure: true});

I have researched and I was advised to put this into the virtual host config file of the domain in Apache2:

Header always set Access-Control-Allow-Origin: "*"

However the error is still the same.

Why am I receiving this error? How can I fix it?

Venelin
  • 2,905
  • 7
  • 53
  • 117
  • If the server is written in Node JS, in the server write `io.set('origins', '*:*');` as per answered question from https://stackoverflow.com/questions/24058157/socket-io-node-js-cross-origin-request-blocked – Ameer Apr 10 '20 at 14:06

0 Answers0