prerender_rails 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +2 -0
- data/lib/prerender_rails.rb +7 -3
- data/prerender_rails.gemspec +1 -1
- data/test/lib/prerender_rails.rb +18 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d43e85db62f63e2851dd12ae260c62183fd9d15d
|
4
|
+
data.tar.gz: e2d6b324f559ee75823216fdf975b4b82a640c5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dcf5e1db1abfe34f98ddde47d8ffa7fb66cebe19e4080555c5a77d068ed626bbad0c44249e4745a8af2cc4e57797944ac47ccb00aa96b3e19dae31ce821343a
|
7
|
+
data.tar.gz: ed2c1c3ba07f330f589f2c15b09bb3822dae1a4e438a851587adfd7b6199830a47b0d6634a69f0da18385c11a3b6bb75a72e314b0dac69d10e4b75ca1ecd04b4
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -32,6 +32,8 @@ or if you have an account on [prerender.io](http://prerender.io) and want to use
|
|
32
32
|
|
33
33
|
## Testing
|
34
34
|
|
35
|
+
When testing make sure you're not using a single threaded application server like default WEBrick one, use Puma or Unicorn.
|
36
|
+
|
35
37
|
If your URLs use a hash-bang:
|
36
38
|
|
37
39
|
If you want to see `http://localhost:5000/#!/profiles/1234`
|
data/lib/prerender_rails.rb
CHANGED
@@ -23,11 +23,13 @@ module Rack
|
|
23
23
|
'outbrain',
|
24
24
|
'pinterest',
|
25
25
|
'developers.google.com/+/web/snippet',
|
26
|
+
'www.google.com/webmasters/tools/richsnippets',
|
26
27
|
'slackbot',
|
27
28
|
'vkShare',
|
28
29
|
'W3C_Validator',
|
29
30
|
'redditbot',
|
30
|
-
'Applebot'
|
31
|
+
'Applebot',
|
32
|
+
'Qwantify'
|
31
33
|
]
|
32
34
|
|
33
35
|
@extensions_to_ignore = [
|
@@ -126,7 +128,7 @@ module Rack
|
|
126
128
|
#if it is a bot and not requesting a resource and is not whitelisted...dont prerender
|
127
129
|
return false if @options[:whitelist].is_a?(Array) && @options[:whitelist].all? { |whitelisted| !Regexp.new(whitelisted).match(request.fullpath) }
|
128
130
|
|
129
|
-
#if it is a bot and not requesting a resource and is
|
131
|
+
#if it is a bot and not requesting a resource and is blacklisted(url or referer)...dont prerender
|
130
132
|
if @options[:blacklist].is_a?(Array) && @options[:blacklist].any? { |blacklisted|
|
131
133
|
blacklistedUrl = false
|
132
134
|
blacklistedReferer = false
|
@@ -155,7 +157,9 @@ module Rack
|
|
155
157
|
headers['X-Prerender-Token'] = @options[:prerender_token] if @options[:prerender_token]
|
156
158
|
req = Net::HTTP::Get.new(url.request_uri, headers)
|
157
159
|
req.basic_auth(ENV['PRERENDER_USERNAME'], ENV['PRERENDER_PASSWORD']) if @options[:basic_auth]
|
158
|
-
|
160
|
+
http = Net::HTTP.new(url.host, url.port)
|
161
|
+
http.use_ssl = true if url.scheme == 'https'
|
162
|
+
response = http.request(req)
|
159
163
|
if response['Content-Encoding'] == 'gzip'
|
160
164
|
response.body = ActiveSupport::Gzip.decompress(response.body)
|
161
165
|
response['Content-Length'] = response.body.length
|
data/prerender_rails.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "prerender_rails"
|
5
|
-
spec.version = "1.
|
5
|
+
spec.version = "1.4.0"
|
6
6
|
spec.authors = ["Todd Hooper"]
|
7
7
|
spec.email = ["todd@prerender.io"]
|
8
8
|
spec.description = %q{Rails middleware to prerender your javascript heavy pages on the fly by a phantomjs service}
|
data/test/lib/prerender_rails.rb
CHANGED
@@ -74,6 +74,17 @@ describe Rack::Prerender do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
|
77
|
+
it "should set use_ssl to true for https prerender_service_url" do
|
78
|
+
@prerender = Rack::Prerender.new(@app, prerender_service_url: 'https://service.prerender.io/')
|
79
|
+
|
80
|
+
request = Rack::MockRequest.env_for "/search/things/123/page?_escaped_fragment_=", "HTTP_USER_AGENT" => bot
|
81
|
+
stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
|
82
|
+
response = @prerender.call(request)
|
83
|
+
|
84
|
+
assert_equal ["<html></html>"], response[2].body
|
85
|
+
end
|
86
|
+
|
87
|
+
|
77
88
|
it "should return a prerendered response if the url is part of the regex specific whitelist" do
|
78
89
|
request = Rack::MockRequest.env_for "/search/things/123/page?_escaped_fragment_=", "HTTP_USER_AGENT" => bot
|
79
90
|
stub_request(:get, @prerender.build_api_url(request)).to_return(:body => "<html></html>")
|
@@ -164,6 +175,13 @@ describe Rack::Prerender do
|
|
164
175
|
end
|
165
176
|
|
166
177
|
|
178
|
+
it "should build the correct https api url with an initialization variable url" do
|
179
|
+
@prerender = Rack::Prerender.new(@app, prerender_service_url: 'https://prerenderurl.com')
|
180
|
+
request = Rack::MockRequest.env_for "https://google.com/search?q=javascript"
|
181
|
+
assert_equal 'https://prerenderurl.com/https://google.com/search?q=javascript', @prerender.build_api_url(request)
|
182
|
+
end
|
183
|
+
|
184
|
+
|
167
185
|
# Check CF-Visitor header in order to Work behind CloudFlare with Flexible SSL (https://support.cloudflare.com/hc/en-us/articles/200170536)
|
168
186
|
it "should build the correct api url for the Cloudflare Flexible SSL support" do
|
169
187
|
request = Rack::MockRequest.env_for "http://google.com/search?q=javascript", { 'CF-VISITOR' => '"scheme":"https"'}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prerender_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Hooper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.0.14
|
121
|
+
rubygems_version: 2.0.14.1
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Prerender your backbone/angular/javascript rendered application on the fly
|