I wrote this light comet implementation
var app = angular.module('App', ['restangular', 'Comet']);
app.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl('http://[private-ip]/my-rest-api/api/v1/');
RestangularProvider.setDefaultHttpFields({timeout: 60*60*24});
});
var comet = angular.module('Comet', []);
comet.factory('CometService', ['Restangular', function(Restangular){
var cometUrl = Restangular.all('comet');
var asteroid = function(cometUrl, callback){
cometUrl.post({user:"Username"}).then(function(data){
callback(data.plain());
asteroid(cometUrl,callback);
})
};
return {
getComet: function(callback){
asteroid(cometUrl,callback);
}
}
}]);
app.controller('Ctrl', ['$scope', 'CometService', function($scope, CometService){
function callback(data){
console.log(data);
}
CometService.getComet(callback);
}]);
It works very well in localhost, but not if the API is called from another host. The same code works fine if I don't use restangular. The API is written in PHP using the Phalcon platform, so all CORS headers are installed. All directories have permission 777. Error 403 was added if I use http: // [private-ip] / my-rest-api / api / v1 / comet url directly in Restangular.all (url) and XMLHttpRequest (OPTION Angular. js 9827) was added with this code.
X mat source
share