0

I have my in the client side an angular module:

angular.module('App')
  .factory('socketClient', function(socketFactory, Auth) {

    // socket.io now auto-configures its connection when we ommit a connection url
    var ioSocket = io('', {
      // Send auth token on connection
      query: 'token=' + Auth.getToken(),
      path:  '/socket.io-client'
    });

    return socketFactory({
    ioSocket: ioSocket
  });;
  });

if I want request for other namespace, I do the next change:

    var ioSocket = io('/test', {
      // Send auth token on connection
      query: 'token=' + Auth.getToken(),
      path:  '/socket.io-client'
    }

But when i do this, I get the follow log in browser.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/socket.io-client/?token=&EIO=3&transport=polling&t=1432867748704-8. (Reason: CORS request failed).

I get this error just when I connect to the namespace.

Sorry for my English. c:

1 Answers1

0

I solved this by:

angular.module('App')
.factory('socketClient', function(socketFactory, $window) {

  // with the full path: $window.location.origin + '/test'
  var ioSocket = io($window.location.origin + '/test', {
    // Send auth token on connection
    query: 'token=' + Auth.getToken(),
    path:  '/socket.io-client'
  });

  return socketFactory({
    ioSocket: ioSocket
  });
});