prerender_rails_embedded 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/prerender_rails_embedded.js +18 -14
- data/lib/prerender_rails_embedded.rb +44 -1
- data/prerender_rails_embedded.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2JmZjlkMzkxMTc2NTA3M2M1NzA1YjY0MTIzODMyMDM1MDk2OTFkOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDVlMjA2MzI1NWI4NjA0MGNkYmM2OTEzOTViNzRjNTQxZjlhMmJmZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzJlMWIxNzQ0NzQzYWJlNTkwM2Y4N2RjMTlkNmMyZGU4OWQ3MWE0MDRkMWQz
|
10
|
+
NWZhYmM2ZWFjN2UwYjQ0NzU3ZDdjODUwMmM4ZjQyZjhlNmU4ZjlkYWE1ZGMw
|
11
|
+
ZjVmMjU4MGM0NDQ3Y2IwNzJlM2MzMDA3NjIwMGU3MjQ1ZjQyMjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjJmNGQ5ZGQzM2JhNzA1MWVjN2UxYmYzNDYwODRlYzZkZmIwZGM2ZmIzODM4
|
14
|
+
NDhmYjYzNTYxYjUwYzQzOTg2ZTQxZWQ3N2U5NmYxYjk3NzY5ZGI3OGYxYzk1
|
15
|
+
YTc3ZGYyZWZiZDY0NWJmYmM2OGJmMzc1MjJlMTY1NjE0YTVlYTg=
|
@@ -68,7 +68,8 @@ surrender.javascriptToExecuteOnPage = function() {
|
|
68
68
|
|
69
69
|
surrender.serveHtml = function(html) {
|
70
70
|
system.stdout.writeLine(html);
|
71
|
-
|
71
|
+
this.logDebug('page returned to rails: ' + page.address);
|
72
|
+
phantom.exit(0);
|
72
73
|
};
|
73
74
|
|
74
75
|
surrender.evaluateJavascriptOnPage = function(t, msPassed) {
|
@@ -79,11 +80,13 @@ surrender.evaluateJavascriptOnPage = function(t, msPassed) {
|
|
79
80
|
|
80
81
|
if(!out.shouldWaitForPrerenderReady || (out.shouldWaitForPrerenderReady && out.prerenderReady) || msPassed >= 20000) {
|
81
82
|
|
82
|
-
if (msPassed >= 20000) _this.
|
83
|
+
if (msPassed >= 20000) _this.logWarning("prerenderReady=true not found after 20s for page: " + page.url);
|
84
|
+
|
85
|
+
_this.logDebug('js evaluated: ' + page.address);
|
86
|
+
_this.serveHtml(out.html);
|
83
87
|
|
84
|
-
_this.serveHtml(out.html);
|
85
88
|
} else {
|
86
|
-
setTimeout(function(){_this.evaluateJavascriptOnPage(_this, msPassed + EVALUATE_JAVASCRIPT_CHECK_TIMEOUT)}, EVALUATE_JAVASCRIPT_CHECK_TIMEOUT);
|
89
|
+
_this.evaluateJavascriptTimeout = setTimeout(function(){_this.evaluateJavascriptOnPage(_this, msPassed + EVALUATE_JAVASCRIPT_CHECK_TIMEOUT)}, EVALUATE_JAVASCRIPT_CHECK_TIMEOUT);
|
87
90
|
}
|
88
91
|
return _this;
|
89
92
|
};
|
@@ -92,32 +95,33 @@ surrender.run = function() {
|
|
92
95
|
var _this = this;
|
93
96
|
|
94
97
|
try {
|
98
|
+
|
95
99
|
page.address = this.removeEscapedFragmentParameter(this.params().address);
|
96
100
|
page.settings.userAgent = 'EtaliaBotAgent';
|
97
|
-
page.settings.resourceTimeout =
|
101
|
+
page.settings.resourceTimeout = 10000;
|
102
|
+
|
103
|
+
_this.logDebug('requested: ' + page.address);
|
104
|
+
|
98
105
|
page.open(page.address, function (st) {
|
106
|
+
_this.logDebug('opened: ' + page.address + 'with status: ' + st);
|
107
|
+
|
99
108
|
if (st !== 'success') throw 'FAIL to load the address';
|
109
|
+
|
100
110
|
_this.evaluateJavascriptOnPage();
|
101
111
|
});
|
112
|
+
|
102
113
|
} catch(e) {
|
114
|
+
_this.logError(e);
|
103
115
|
console.log(e);
|
104
116
|
phantom.exit(1);
|
105
117
|
}
|
106
118
|
|
107
119
|
page.onError = function(message, trace) {
|
108
120
|
_this.logError(message);
|
109
|
-
|
110
|
-
//if (trace && trace.length) {
|
111
|
-
// msgStack.push('TRACE:');
|
112
|
-
// trace.forEach(function(t) {
|
113
|
-
// msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
|
114
|
-
// });
|
115
|
-
//}
|
116
|
-
// console.log(msgStack.join('\n'));
|
117
121
|
};
|
118
122
|
|
119
123
|
page.onConsoleMessage = function(message, lineNum, sourceId) {
|
120
|
-
_this.logInfo('CONSOLE: ' + message + '(' + sourceId + '/L#"' + lineNum + '")');
|
124
|
+
//_this.logInfo('CONSOLE: ' + message + '(' + sourceId + '/L#"' + lineNum + '")');
|
121
125
|
};
|
122
126
|
|
123
127
|
page.onResourceTimeout = function(request) {
|
@@ -1,8 +1,51 @@
|
|
1
1
|
module PrerenderRailsEmbedded
|
2
|
+
require 'timeout'
|
2
3
|
require 'phantomjs'
|
3
4
|
|
4
5
|
def self.flatten_js_to_html(url)
|
5
|
-
|
6
|
+
out = ''
|
7
|
+
thread = nil
|
8
|
+
pid = -1
|
9
|
+
begin
|
10
|
+
Timeout::timeout(30) do
|
11
|
+
thread = Thread.new do
|
12
|
+
IO.popen(phantomjs_invocation(url)) do |io|
|
13
|
+
pid = io.pid
|
14
|
+
Rails.logger.debug("Spawing new phantomjs processo with pid: #{pid}")
|
15
|
+
io.read
|
16
|
+
end
|
17
|
+
end
|
18
|
+
out += thread.value
|
19
|
+
end
|
20
|
+
rescue Timeout::Error
|
21
|
+
Rails.logger.debug('triggering timed out')
|
22
|
+
|
23
|
+
if pid_exists?(pid)
|
24
|
+
Rails.logger.warn("phantomjs with pid##{pid} timed out")
|
25
|
+
|
26
|
+
Process.kill 9, pid
|
27
|
+
out += '<html><head><meta name="robots" content="noindex, noarchive " /></head><body></body></html>'
|
28
|
+
end
|
29
|
+
if thread && thread.alive?
|
30
|
+
Thread.kill(thread)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
out
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def self.pid_exists?(pid)
|
38
|
+
begin
|
39
|
+
Process.kill 0, pid
|
40
|
+
return true
|
41
|
+
rescue Errno::ESRCH
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.phantomjs_invocation(url)
|
48
|
+
[Phantomjs.path , '--load-images=false', '--ignore-ssl-errors=true', '--ssl-protocol=TLSv1', '--disk-cache=yes', '--max-disk-cache-size=524228', "#{File.dirname(__FILE__)}/prerender_rails_embedded.js", url]
|
6
49
|
end
|
7
50
|
|
8
51
|
def self.local_renderer
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'prerender_rails_embedded'
|
5
|
-
spec.version = '0.2.
|
5
|
+
spec.version = '0.2.8'
|
6
6
|
spec.authors = ['Gian Carlo Pace', 'Luca Mirra']
|
7
7
|
spec.email = %w(giancarlo.pace@etalia.net)
|
8
8
|
spec.description = %q{A plugin for prerender_rails middleware to render JavaScript web app on the fly calling phantomjs directly}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prerender_rails_embedded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gian Carlo Pace
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-01-
|
12
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.4.5
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: Prerender your backbone/angular/javascript rendered application on the fly
|