PatrickJS / angular-websocket

:arrow_upper_left: The missing Angular WebSocket module for connecting client applications to servers by @AngularClass
https://angularclass.github.io/angular-websocket
MIT License
1.22k stars 195 forks source link

Fetch API cannot load http://echo.websocket.org/. No 'Access-Control-Allow-Origin' #90

Closed RylanGotto closed 8 years ago

RylanGotto commented 8 years ago

Fetch API cannot load http://echo.websocket.org/. No 'Access-Control-Allow-Origin'

This is how I am defining everything just for a test in an angular seed project. For some reason it made me define the buffer type for some reason, in which case I am getting the following

Fetch API cannot load http://echo.websocket.org/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8200' is therefore not allowed access. The response had HTTP status code 404. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Any tips would be greatly appreciated.

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 'use strict';

angular.module('dgmd.game.view', ['ngRoute', 'angular-websocket'])

  .config(['$routeProvider', function($routeProvider) {
      $routeProvider.when('/game', {
      templateUrl: 'game/game.html',
      controller: 'GameCtrl'
     });
 }])

 .controller('GameCtrl', ['$websocket', function($websocket) {

  var dataStream = $websocket('ws://echo.websocket.org', [], {binaryType: "arraybuffer"});

  var collection = [];

  dataStream.onMessage(function(message) {
    collection.push(JSON.parse(message.data));
  });

  dataStream.onOpen(function(message) {
    console.log('open')
  });

}]);