In nodejs mando un flusso di clienti in questo modo:Come leggere un flusso nodejs in angolare?
DockerService.get().pull('my/image', function(err, stream) {
if (err) {
return res.badRequest(err);
} else {
return stream.pipe(res);
}
});
Questo viene attivato da un client angularjs utilizzando $ http.get:
pull: function() {
var url = ENV.apiEndpoint + '/docker/pull';
var promise = $http.get(url).success(function(response) {
return response;
}).error(function(data, status) {
});
return promise;
}
Tuttavia non riesco a leggere il flusso. Da angolare ricevo un messaggio di errore:
SyntaxError: Unexpected token {
at Object.parse (native)
at fromJson (file://build/vendor/angular/angular.js:1065:14)
at defaultHttpResponseTransform (file://build/vendor/angular/angular.js:8579:16)
at file://build/vendor/angular/angular.js:8664:12
at forEach (file://build/vendor/angular/angular.js:323:20)
at transformData (file://build/vendor/angular/angular.js:8663:3)
at transformResponse (file://build/vendor/angular/angular.js:9389:23)
at processQueue (file://build/vendor/angular/angular.js:13189:27)
at file://build/vendor/angular/angular.js:13205:27
at Scope.$get.Scope.$eval (file://build/vendor/angular/angular.js:14401:28)
non riesco a trovare tutte le informazioni su come gestire i flussi in angolare. Mi puoi aiutare?
intestazioni:
La risposta è troppo grande per presentarlo qui ecco la prima parte di esso:
anteprima:
Potete mostrare le intestazioni HTTP e il corpo che il codice server restituisce? La mia ipotesi è che tu abbia un'intestazione "Content-Type" non corrispondente per l'applicazione/json ma un corpo di testo in chiaro da "badRequest (err)". –
@PeterLyons La richiesta get stessa restituisce 200 OK. Nella scheda di rete di Chrome posso vedere la risposta in pipe. Tuttavia in angolare viene attivato il callback dell'errore. La risposta è di tipo JSON. badRequest non viene chiamato affatto. –
vedere qui se funziona per voi http: // StackOverflow.it/questions/26300350/handling-nodejs-streams-with-angularjs –