angularjssocket.iocorssteroidssupersonic

Socket.io angularjs client not connected due to CORS error


I recently ported an app over from Ionic framework. My app utilized socket.io, which worked flawlessly in ionic.

It does not work properly in steroids / supersonic. I am getting the following when the client tries to connect to my nodejs server using socket.io:

Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.

Why am I getting this in supersonic when I did not have this error in ionic? Currently the server has the following in .htaccess:

Header set Access-Control-Allow-Origin http://localhost:8100

My socket.io script is loaded in common/layout.html which means it gets loaded with all views in the app.

The node.js server has not changed and is configured similar to the basic socket.io docs.

I am stumped. There are a million and one posts around the net about this particular error with a million and one suggestions on how to fix......none of which has helped me solve this. Since this is a mobile hybrid app, there won't be an origin sent from the client when the app is running on a real device. But for now I am on the iOS emulator and using Safari inspector to see why I can't keep a socket.io connection.

I have tried to use the express cors package and other method to override the '*' wildcard setting with a specific origin:

http://localhost:8100

Nothing seems to help.


Solution

  • The Supersonic app had config settings in app.coffee like this:

    network:
    extraResponseHeaders:
    "Access-Control-Allow-Origin": "*"
    "Access-Control-Allow-Headers": "Content-Type, X-Requested-With"
    

    as documented here:

    http://docs.appgyver.com/supersonic/guides/architecture/app-config-files/#app-coffee

    What a nightmare hack for using socket.io (and probably other web services)!!!

    I changed to :

    "Access-Control-Allow-Origin": "http://localhost"
    

    ...and was able to connect with my socket.io server.