Search code examples
angularjsnode.jsexpressseoprerender

Prerender.io not caching my pages


So I'm trying to set up prerender.io for my AngularJS application with a ExpressJS backend following this tutorial. I have done exactly as instructed, the only difference being I have enabled HTML5mode. I have included the meta(name="fragment" content="!") in my index.jade and the prerender token to my server.js file (using the prerender-node package) but somehow my pages do not seem to be cached or generate any crawl stats.

config.coffee

angular.config ['$stateProvider','$urlRouterProvider','$locationProvider','toastrConfig',($stateProvider, $urlRouterProvider,$locationProvider,toastrConfig)->
    $stateProvider
    .state 'home',
        url:'/'
        templateUrl: 'html/main.html'
        controller:'mainController'

    $urlRouterProvider.otherwise '/'

    $locationProvider.html5Mode
        enabled: true
        requireBase: false

    $locationProvider.hashPrefix '!'
]

Server.JS

// Here we require the prerender middleware that will handle requests from Search Engine crawlers 
// We set the token only if we're using the Prerender.io service 
app.use(require('prerender-node')
.set('prerenderServiceUrl', 'http://www.mydomain.co.com/')
.set('prerenderToken', 'my-token'));


// HTML5MODE settings
// ------------------------------------------------------
app.use('/js', express.static(__dirname + '/public/js'));
app.use('/css', express.static(__dirname + '/public/css'));
app.use('/html', express.static(__dirname + '/public/html'));

// Routes
// ------------------------------------------------------
require('./app/js/routes/routes.js')(app);

app.all('/*', function(req, res, next) {
    // Just send the index.html for other files to support HTML5Mode
    res.sendFile('/public/index.html', { root: __dirname });
});

Solution

  • You should remove this line from your config:

    .set('prerenderServiceUrl', 'http://www.mydomain.co.com/')
    

    The service URL should point to a Prerender server, so you shouldn't set that to your website URL.