Whenever I try to establish a socket connection (from client) with my server (writen in nodejs), I get a cors error Access to XMLHttpRequest at 'https://example.onrender.com/socket.io/?EIO=4&transport=polling&t=P1g4kQB' from origin 'http://another-example-website.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Even though I have specified the cors origin, it still does not work. My backend code (nodejs) is the following:
const http = require('http').createServer();
const io = require("socket.io")(http, {
cors: { origin: "*" }
});
let userList = []
io.on("connection", (socket) => {
console.log(socket.id)
});
Weirdly enough, it does not show any errors when I host the server on my computer, when I host it on render (free hosting site for servers), it comes up with this error. I do not know if it is something to do with the code or an external factor.