I am making a mobile app with node.js REST API as backend and Angular as frontend both will be on different server. the angular app will later be on attached with phonegap to make it hybrid App. I am using socket.io and try to connect the front end to back end to built a built a chat.
I am getting an error when I try to connect the socket through
io.connect("(http://localhost:3000/")
XMLHttpRequest cannot load
http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1412172739903-3
. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin
'http://localhost:1235'
is therefore not allowed access.
In your NodeJS serverside code (Assume if you used ExpressJS in backend), did you add
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
This site might help you: Enable cors in serverside
I recommend use https://www.npmjs.org/package/cors
This module enable http://en.wikipedia.org/wiki/Cross-origin_resource_sharing on you're apps