I am trying to access the Node.js socket.io server from my cordova app. And then I receive the following error:
Failed to load https://www.ride4you.co.il/socket.io/?EIO=3&transport=polling&t=M30S1z4: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://127.0.0.1:8080' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
This is the connection code in client side (the app or localhost):
<script src="https://www.ride4you.co.il/socket.io/socket.io.js">
</script>
<script type="text/javascript">
var socket = io("https://www.ride4you.co.il");
socket.on("disconnect", function() {
console.log("Disconnected");
socket = io();
console.log("Connected");
});
</script>
When I am trying this code from the actual domain, no errors and everything works. But from the app, which is not the origin domain, there is a block.
I have tried to remove this block, and allow every origin to access this socket with the next code in app.js (main node.js file):
var express = require('express');
var app = express();
var server = require('http').createServer(app);
global.io = require('socket.io').listen(server);
io.set('origins', '*:*');
But still got the same error there.
I know there is an option to allow for a specific domain, but I am using a cordova app which does not have a domain - so I think that is should be allowed by everyone, is not it?
Thanks.