Implementing prerender.io middleware in sails.js

738 views Asked by At

I have an angular site running on a sails.js backend. I am trying to implement the prerender.io service for my site so that my site can be indexed by search engines.

The problem I am running into is that the setup instructions for their node module are specifically for express. Basically they want you to set up this middleware:

app.use(require('prerender-node').set('prerenderToken', 'r8c9lN6JsUMMfpzYNlht'));

Sails doesn't set up middleware this way, but rather through it's policies (for the most part, anyway).

This question was raised some time ago here, however it seems it was simply added to a list and never actually addressed.

I have also looked at this: How to use custom route middleware with Sails.js? (ExpressJS)

and have attempted implementing the customMiddleware solution, but to no avail.

Any ideas how to set this up in sails?

1

There are 1 answers

1
Prerender.io On BEST ANSWER

If you look at this issue: https://github.com/prerender/prerender/issues/12

@talss89 was able to get it working using config/http.js:

module.exports.http = {
    middleware: {

     prerender: require('prerender-node').set('prerenderToken', 'YOUR_TOKEN'),
     order: [
       'startRequestTimer',
       'cookieParser',
       'session',
       'myRequestLogger',
       'bodyParser',
       'handleBodyParserError',
       'prerender',
       'compress',
       'methodOverride',
       'poweredBy',
       '$custom',
       'router',
       'www',
       'favicon',
       '404',
       '500'
     ]
  }
};