prerender_rails_embedded 0.2.8 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/prerender_rails_embedded.js +30 -8
- data/lib/prerender_rails_embedded.rb +1 -1
- data/prerender_rails_embedded.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzkxNDRhNzk4NzZiOWU3YWM2OTBiZjUyMmQ2NTg5MzAxZTNmMWE2Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDBhMzNiYTM2YjU2YjNiMTZhNDc4ZTU5NDFlZjdjNzgxMTFhNzEyNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjE1M2RhYjk3YTUxMGM4YmNmOWYxYzY0ZGI1NTE4NjQwNjZlN2I4NGE5Zjk1
|
10
|
+
MGEyMjM2NjEzYjliZGI1OTFkZTNkNDYxYTViODUxMzE0MWY2Y2EyZDRjN2Zh
|
11
|
+
YmM1MzNhZWE3NWJmOTNmYmQzZDI2NzJmZGY5YTVjNmE0ZGFmNjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDk2MjhjZGE2YjgwNDU5ZTg2MzM1NTcxYjYzYzkzNmE2NGIwY2JkNzdhMzYz
|
14
|
+
MWY4ZmZiYjA2MjBjOGM4ODZkNTY1YTE5MmNjMjM4MTBiMTQ3NWEyODBjODA3
|
15
|
+
YTEyYjg0OGZjYmIzNjEwNmY1YTY4MGVjOTU2MmZhMWQ5ZjVlNDY=
|
@@ -25,7 +25,17 @@ surrender.params = function() {
|
|
25
25
|
|
26
26
|
|
27
27
|
surrender.javascriptToExecuteOnPage = function() {
|
28
|
+
function removeTag(tagName) {
|
29
|
+
var element = document.getElementsByTagName(tagName);
|
30
|
+
for (var index = element.length - 1; index >= 0; index--) {
|
31
|
+
element[index].parentNode.removeChild(element[index]);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
28
35
|
var processHtml = function() {
|
36
|
+
removeTag('script');
|
37
|
+
removeTag('iframe');
|
38
|
+
|
29
39
|
if (!window.prerenderRailsEmbedded || !window.prerenderRailsEmbedded.filterHtmlOutput || typeof(window.prerenderRailsEmbedded.filterHtmlOutput) !== "function") {
|
30
40
|
return document.documentElement.outerHTML;
|
31
41
|
} else {
|
@@ -66,9 +76,14 @@ surrender.javascriptToExecuteOnPage = function() {
|
|
66
76
|
}
|
67
77
|
};
|
68
78
|
|
79
|
+
surrender.millisElapsed = function () {
|
80
|
+
return new Date().getTime() - this.requestStarted.getTime();
|
81
|
+
};
|
82
|
+
|
69
83
|
surrender.serveHtml = function(html) {
|
70
84
|
system.stdout.writeLine(html);
|
71
|
-
|
85
|
+
|
86
|
+
this.logDebug('page returned to rails: ' + page.address + " (" + this.millisElapsed() + "ms)");
|
72
87
|
phantom.exit(0);
|
73
88
|
};
|
74
89
|
|
@@ -82,7 +97,6 @@ surrender.evaluateJavascriptOnPage = function(t, msPassed) {
|
|
82
97
|
|
83
98
|
if (msPassed >= 20000) _this.logWarning("prerenderReady=true not found after 20s for page: " + page.url);
|
84
99
|
|
85
|
-
_this.logDebug('js evaluated: ' + page.address);
|
86
100
|
_this.serveHtml(out.html);
|
87
101
|
|
88
102
|
} else {
|
@@ -96,11 +110,12 @@ surrender.run = function() {
|
|
96
110
|
|
97
111
|
try {
|
98
112
|
|
99
|
-
page.address = this.removeEscapedFragmentParameter(this.params().address);
|
113
|
+
page.address = this.replaceHostWithLocalhost(this.removeEscapedFragmentParameter(this.params().address));
|
100
114
|
page.settings.userAgent = 'EtaliaBotAgent';
|
101
|
-
page.settings.resourceTimeout =
|
115
|
+
page.settings.resourceTimeout = 15000;
|
102
116
|
|
103
117
|
_this.logDebug('requested: ' + page.address);
|
118
|
+
surrender.requestStarted = new Date();
|
104
119
|
|
105
120
|
page.open(page.address, function (st) {
|
106
121
|
_this.logDebug('opened: ' + page.address + 'with status: ' + st);
|
@@ -121,16 +136,19 @@ surrender.run = function() {
|
|
121
136
|
};
|
122
137
|
|
123
138
|
page.onConsoleMessage = function(message, lineNum, sourceId) {
|
124
|
-
|
139
|
+
_this.logInfo('CONSOLE: ' + message + '(' + sourceId + '/L#"' + lineNum + '")');
|
125
140
|
};
|
126
141
|
|
127
142
|
page.onResourceTimeout = function(request) {
|
128
143
|
console.log('<html><head><meta name="robots" content="noindex, noarchive" /></head><body></body></html>');
|
129
144
|
_this.logWarning('Response (#' + request.id + '): ' + JSON.stringify(request));
|
130
145
|
setTimeout(function() { phantom.exit(1); }, 0); // workaround to avoid PhantomJS crashes
|
131
|
-
}
|
132
|
-
};
|
146
|
+
};
|
133
147
|
|
148
|
+
//page.onResourceRequested = function(requestData, networkRequest) {
|
149
|
+
// _this.logWarning('-------- (#' + requestData.id + '): ' + requestData.url + ' ' + JSON.stringify(requestData.headers));
|
150
|
+
//};
|
151
|
+
};
|
134
152
|
surrender.removeEscapedFragmentParameter = function (addressUrl) {
|
135
153
|
var parts = new URI(addressUrl);
|
136
154
|
|
@@ -148,13 +166,17 @@ surrender.removeEscapedFragmentParameter = function (addressUrl) {
|
|
148
166
|
return newUrl;
|
149
167
|
};
|
150
168
|
|
169
|
+
surrender.replaceHostWithLocalhost = function (addressUrl) {
|
170
|
+
this.logDebug(new URI(addressUrl).hostname('localhost'));
|
171
|
+
return new URI(addressUrl).hostname('localhost');
|
172
|
+
};
|
173
|
+
|
151
174
|
surrender.logFilePath = function() {
|
152
175
|
if (fs.exists("/opt/sites/frontend/current/log"))
|
153
176
|
return "/opt/sites/frontend/current/log";
|
154
177
|
else
|
155
178
|
return "/tmp";
|
156
179
|
};
|
157
|
-
|
158
180
|
surrender.flog = function(message) {
|
159
181
|
try {
|
160
182
|
fs.write(this.logFilePath() + '/etalia-prerender.log', message + "\n", 'a');
|
@@ -45,7 +45,7 @@ module PrerenderRailsEmbedded
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def self.phantomjs_invocation(url)
|
48
|
-
[Phantomjs.path , '--load-images=false', '--ignore-ssl-errors=true', '--ssl-protocol=TLSv1', '--disk-cache=
|
48
|
+
[Phantomjs.path , '--load-images=false', '--ignore-ssl-errors=true', '--ssl-protocol=TLSv1', '--disk-cache=true', '--max-disk-cache-size=524228', "#{File.dirname(__FILE__)}/prerender_rails_embedded.js", url]
|
49
49
|
end
|
50
50
|
|
51
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.10'
|
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.10
|
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-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|