Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to stop next middleware processing upon options.stopNext=true #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koa-prerender",
"version": "1.0.3",
"version": "1.0.4",
"description": "",
"main": "index.js",
"scripts": {
Expand Down