prerendercloud 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +20 -0
- data/lib/prerendercloud.rb +16 -6
- data/prerendercloud.gemspec +1 -1
- data/test/lib/prerendercloud.rb +21 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f83eade04762849473e28d6066c6e143da296e0b
|
4
|
+
data.tar.gz: a4abe2d1c5ca27b28bbe8275c3c678d7cae57f1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3770ad267d006931870230dc2ec647d4941f8c1fa983e24ec8c6777c5f76170396a745fc90a7f2cd86c23eb597ec52f90a0f21a9c0dfc5b41e857873b9deaa53
|
7
|
+
data.tar.gz: b28db95acb7e77148964215051e4a9b676e976f7b6075505e9851e830163fa9a646d362f3cb1de4c4f9bf9a375202d490681cb8397e23299c52c6f5907901181
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -37,3 +37,23 @@ but it's here if you want it:
|
|
37
37
|
```ruby
|
38
38
|
config.middleware.use Rack::Prerendercloud, bots_only: true
|
39
39
|
```
|
40
|
+
|
41
|
+
### Blacklist
|
42
|
+
|
43
|
+
Prevent certain paths from being prerendered (e.g. JSON API endpoints)
|
44
|
+
|
45
|
+
Pass an array of Regexps or Strings.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
config.middleware.use Rack::Prerender, blacklist: [/^\/api/, '/housing_prices.json']
|
49
|
+
```
|
50
|
+
|
51
|
+
### Whitelist
|
52
|
+
|
53
|
+
Only allow certain paths to be prerendered
|
54
|
+
|
55
|
+
Pass an array of Regexps or Strings.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
config.middleware.use Rack::Prerender, whitelist: [/^\/users/, '/ips-v4']
|
59
|
+
```
|
data/lib/prerendercloud.rb
CHANGED
@@ -125,19 +125,29 @@ module Rack
|
|
125
125
|
is_requesting_prerendered_page = true if Rack::Utils.parse_query(request.query_string).has_key?('_escaped_fragment_')
|
126
126
|
|
127
127
|
# if whitelist exists and path is not whitelisted...don't prerender
|
128
|
-
return false if @options[:whitelist].is_a?(Array) && @options[:whitelist].all?
|
128
|
+
return false if @options[:whitelist].is_a?(Array) && @options[:whitelist].all? do |whitelisted|
|
129
|
+
if whitelisted.is_a?(Regexp)
|
130
|
+
!whitelisted.match(request.fullpath)
|
131
|
+
else
|
132
|
+
whitelisted != request.fullpath;
|
133
|
+
end
|
134
|
+
end
|
129
135
|
|
130
136
|
# if blacklist exists and path is blacklisted(url or referer)...don't prerender
|
131
|
-
if @options[:blacklist].is_a?(Array) && @options[:blacklist].any?
|
137
|
+
if @options[:blacklist].is_a?(Array) && @options[:blacklist].any? do |blacklisted|
|
132
138
|
blacklistedUrl = false
|
133
139
|
blacklistedReferer = false
|
134
|
-
regex = Regexp.new(blacklisted)
|
135
140
|
|
136
|
-
|
137
|
-
|
141
|
+
if blacklisted.is_a?(Regexp)
|
142
|
+
blacklistedUrl = !!blacklisted.match(request.fullpath)
|
143
|
+
blacklistedReferer = !!blacklisted.match(request.referer) if request.referer
|
144
|
+
else
|
145
|
+
blacklistedUrl = blacklisted == request.fullpath
|
146
|
+
blacklistedReferer = request.referer && blacklisted == request.referer
|
147
|
+
end
|
138
148
|
|
139
149
|
blacklistedUrl || blacklistedReferer
|
140
|
-
|
150
|
+
end
|
141
151
|
return false
|
142
152
|
end
|
143
153
|
|
data/prerendercloud.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "prerendercloud"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.2.0"
|
6
6
|
spec.authors = ["Jonathan Otto"]
|
7
7
|
spec.email = ["support@prerender.cloud"]
|
8
8
|
spec.description = %q{Rack middleware to server-side render your JavaScript apps by prerender.cloud}
|
data/test/lib/prerendercloud.rb
CHANGED
@@ -89,14 +89,6 @@ describe Rack::Prerendercloud do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
|
92
|
-
it "should continue to app routes if the url is not part of the regex specific whitelist" do
|
93
|
-
request = Rack::MockRequest.env_for "/saved/search/blah?_escaped_fragment_=", "HTTP_USER_AGENT" => bot
|
94
|
-
response = Rack::Prerendercloud.new(@app, whitelist: ['^/search', '/help']).call(request)
|
95
|
-
|
96
|
-
assert_equal "", response[2]
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
92
|
it "should set use_ssl to true for https prerender_service_url" do
|
101
93
|
@prerender = Rack::Prerendercloud.new(@app, prerender_service_url: 'https://service.prerender.cloud/')
|
102
94
|
|
@@ -108,10 +100,18 @@ describe Rack::Prerendercloud do
|
|
108
100
|
end
|
109
101
|
|
110
102
|
|
103
|
+
it "should continue to app routes if the url is not part of the regex specific whitelist" do
|
104
|
+
request = Rack::MockRequest.env_for "/saved/search/blah?_escaped_fragment_=", "HTTP_USER_AGENT" => bot
|
105
|
+
response = Rack::Prerendercloud.new(@app, whitelist: [/^\/search/, '/help']).call(request)
|
106
|
+
|
107
|
+
assert_equal "", response[2]
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
111
|
it "should return a prerendered response if the url is part of the regex specific whitelist" do
|
112
112
|
request = Rack::MockRequest.env_for "/search/things/123/page?_escaped_fragment_=", "HTTP_USER_AGENT" => bot
|
113
113
|
stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
|
114
|
-
response = Rack::Prerendercloud.new(@app, whitelist: [
|
114
|
+
response = Rack::Prerendercloud.new(@app, whitelist: [/^\/search.*page/, '/help']).call(request)
|
115
115
|
|
116
116
|
assert_equal ["<html></html>"], response[2].body
|
117
117
|
end
|
@@ -119,14 +119,14 @@ describe Rack::Prerendercloud do
|
|
119
119
|
|
120
120
|
it "should continue to app routes if the url is part of the regex specific blacklist" do
|
121
121
|
request = Rack::MockRequest.env_for "/search/things/123/page", "HTTP_USER_AGENT" => bot
|
122
|
-
response = Rack::Prerendercloud.new(@app, blacklist: [
|
122
|
+
response = Rack::Prerendercloud.new(@app, blacklist: [/^\/search/, '/help']).call(request)
|
123
123
|
|
124
124
|
assert_equal "", response[2]
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should continue to app routes if the hashbang url is part of the regex specific blacklist" do
|
128
128
|
request = Rack::MockRequest.env_for "?_escaped_fragment_=/search/things/123/page", "HTTP_USER_AGENT" => bot
|
129
|
-
response = Rack::Prerendercloud.new(@app, blacklist: [
|
129
|
+
response = Rack::Prerendercloud.new(@app, blacklist: [/\/search/, '/help']).call(request)
|
130
130
|
|
131
131
|
assert_equal "", response[2]
|
132
132
|
end
|
@@ -134,24 +134,30 @@ describe Rack::Prerendercloud do
|
|
134
134
|
it "should return a prerendered response if the url is not part of the regex specific blacklist" do
|
135
135
|
request = Rack::MockRequest.env_for "/profile/search/blah", "HTTP_USER_AGENT" => bot
|
136
136
|
stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
|
137
|
-
response = Rack::Prerendercloud.new(@app, blacklist: [
|
137
|
+
response = Rack::Prerendercloud.new(@app, blacklist: [/^\/search/, '/help']).call(request)
|
138
138
|
|
139
139
|
assert_equal ["<html></html>"], response[2].body
|
140
140
|
end
|
141
141
|
|
142
142
|
|
143
|
-
it "should continue to app routes if the referer is part of the regex specific blacklist" do
|
143
|
+
it "should continue to app routes if the referer is part of the regex specific blacklist (regex match)" do
|
144
144
|
request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/search'
|
145
|
-
response = Rack::Prerendercloud.new(@app, blacklist: [
|
145
|
+
response = Rack::Prerendercloud.new(@app, blacklist: [/^\/search/, '/help']).call(request)
|
146
146
|
|
147
147
|
assert_equal "", response[2]
|
148
148
|
end
|
149
149
|
|
150
|
+
it "should continue to app routes if the referer is part of the regex specific blacklist (string match)" do
|
151
|
+
request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/search'
|
152
|
+
response = Rack::Prerendercloud.new(@app, blacklist: ['/search', '/help']).call(request)
|
153
|
+
|
154
|
+
assert_equal "", response[2]
|
155
|
+
end
|
150
156
|
|
151
157
|
it "should return a prerendered response if the referer is not part of the regex specific blacklist" do
|
152
158
|
request = Rack::MockRequest.env_for "/api/results", "HTTP_USER_AGENT" => bot, "HTTP_REFERER" => '/profile/search'
|
153
159
|
stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
|
154
|
-
response = Rack::Prerendercloud.new(@app, blacklist: [
|
160
|
+
response = Rack::Prerendercloud.new(@app, blacklist: [/^\/search/, '/help']).call(request)
|
155
161
|
|
156
162
|
assert_equal ["<html></html>"], response[2].body
|
157
163
|
end
|