lundi 2 mars 2015

Angular SEO + Phantom + Node: fetching and rendering data

I followed the tutorial here in order to get my app html pre-renderered.



The problem is i am unable to get the fetched data rendered properly in the view when i curl the Phantom server - i.e. curl 'http://localhost:9090/?_escaped_fragment_=/news'.


In the node.js server i am using the cors module to whitelist domains and a Mongo database.


In the Angular controller:



$http.get('http://localhost:8000/news').
success(function(data, status, headers, config) {
$scope.news = data;
$scope.htmlReady();
}).
error(function(data, status, headers, config) {
console.log("cloud not get dat..");
});


But the $scope.htmlReady() never gets called. In fact never enters the success method and goes directly to the error.


In short:



  • Requests are being correctly made to the server

  • Data is correctly fetched in node

  • The ng-view loads the controller's template correctly

  • By some reason succes method is never getting called, so data never gets binded in scope.


I am guessing res.send(myData) in node is maybe trying to send back the response to localhost:9000 (grunt) not to localhost:9090 (phantom) but just guessing..


Any ideas?


Aucun commentaire:

Enregistrer un commentaire