Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx/angular/node.js root URL with prerender.io

We have an angular SPA using node, nginx, and prerender.io. Our home page is set as a unique url (i.e. www.foo.com/bar) and in our routing, this home page captures the default redirect of all root-relative urls not specifically routed otherwise.

Our problem is this: the root url www.foo.com or www.foo.com/ comes back with a blank page scrape for google and Facebook. Our index is an ng-include basic template that all pages are inserted inside of, so it makes sense that our root url comes back without any real html body content. Main html in index:

<div class="st-content">
  <div ng-view="" class="main-content" id="mainView"></div>
  <div ng-include="'/views/footer.html'"></div>
</div> 

Additionally, we have tried other solutions without positive results:

  • base tag in the index head linking to '/', which did not break anything… it also did not resolve it
  • 307 redirect, no results
  • nginx configs look good

Note: in writing this question it occurred to me to change the home routing to ‘/':

.when('/', {
    templateUrl: '/views/foo-bar.html',
    title: ‘Foo Bar',
    pageDescription: ‘Lorem Ipsum Foo Bar'
})
    .
    .
    .
.otherwise({
    redirectTo: '/'
});

If changed to this will the home scrape still show as blank? Isn’t this basically the same js redirect problem, but with less characters?

like image 432
htx-ui Avatar asked Mar 16 '15 15:03

htx-ui


1 Answers

You need to set the window.prerenderReady variable. Thus, put this in your route controller:

window.prerenderReady = false;

... and this in your controller's success callback function:

window.prerenderReady = true;

like image 152
Karma Avatar answered Oct 15 '22 00:10

Karma