diff --git a/README.md b/README.md index 614933c..8340009 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ var options = { protocol: 'http', // optional, default: this.protocol host: 'www.risingstack.com' // optional, default: this.host, prerenderToken: '' // optional or process.env.PRERENDER_TOKEN + stopNext: true // optional, if true it will not allow next middleware to continue and instead return the response. }; // Use as middleware diff --git a/index.js b/index.js index ef35b1a..3e72dcb 100644 --- a/index.js +++ b/index.js @@ -82,10 +82,6 @@ function shouldPreRender (options) { return options.url.indexOf(extension) !== -1; }); - var isBot = crawlerUserAgents.some(function (crawlerUserAgent) { - return options.userAgent.toLowerCase().indexOf(crawlerUserAgent.toLowerCase()) !== -1; - }); - // do not pre-rend when: if (!options.userAgent) { return false; @@ -95,6 +91,10 @@ function shouldPreRender (options) { return false; } + var isBot = crawlerUserAgents.some(function (crawlerUserAgent) { + return options.userAgent.toLowerCase().indexOf(crawlerUserAgent.toLowerCase()) !== -1; + }); + if (hasExtensionToIgnore) { return false; } @@ -167,7 +167,9 @@ module.exports = function preRenderMiddleware (options) { body = response[1] || ''; - yield* next; + if (!options.stopNext) { + yield * next; + } this.body = body.toString(); this.set('X-Prerender', 'true'); diff --git a/package.json b/package.json index 5035dc2..873936c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "koa-prerender", - "version": "1.0.3", + "version": "1.0.4", "description": "", "main": "index.js", "scripts": {