prerender_rails_embedded 0.2.3 → 0.2.4
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 +53 -12
- 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
|
+
MTkwOTdiZGVhZWY0YjM1YWZlNDI4MzY3YjJhMGQxZGZjNTY2MDE1Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZmMzZmI2ZTJjOWMyYWRhNzUxYmNiM2QzMmM3MzQwNTg4ZGM4MTIwYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmJlNjJkZTNhZDQ5ZTNhZWYxNzA2YzBmZGY4YzY4ZWM0NzQzZTkyOTUxNDIz
|
10
|
+
ODA2NGU1ZTg5OGJmOTc5ZjU3NzQ2ZWEyNjQyYzFmNmE4MjIwMzgwMTg0MmI2
|
11
|
+
NTQ1NTY0OGI4MGNiOTkwMzdlZTViNGJkZjM5NzYwYmEzY2VjOTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjQ1MGY4ZWMyNTg5NjFkY2IzZWRkY2VlNDI2ODc1ZjY5ZmUzNDI2ODk3OThh
|
14
|
+
OWVkMzQxZTMzMDQ2NjNlNzZlYjllY2E0ZTQ5MWMwNDVmZjZhYTNkMjVmZTU1
|
15
|
+
NTJlNTM3YjVjMWY4NjcxN2M3M2RhMWEyMTVjYTg0YTM5ZDFhMmY=
|
@@ -8,7 +8,8 @@ var EVALUATE_JAVASCRIPT_CHECK_TIMEOUT = 50;
|
|
8
8
|
|
9
9
|
var page = require('webpage').create(),
|
10
10
|
system = require('system'),
|
11
|
-
URI = require('./URI')
|
11
|
+
URI = require('./URI'),
|
12
|
+
fs = require('fs');
|
12
13
|
|
13
14
|
var surrender = {};
|
14
15
|
page.viewportSize = {
|
@@ -84,10 +85,12 @@ surrender.evaluateJavascriptOnPage = function(t) {
|
|
84
85
|
};
|
85
86
|
|
86
87
|
surrender.run = function() {
|
88
|
+
var _this = this;
|
89
|
+
|
87
90
|
try {
|
88
|
-
var _this = this;
|
89
91
|
page.address = this.removeEscapedFragmentParameter(this.params().address);
|
90
92
|
page.settings.userAgent = 'EtaliaBotAgent';
|
93
|
+
page.settings.resourceTimeout = 300;
|
91
94
|
page.open(page.address, function (st) {
|
92
95
|
if (st !== 'success') throw 'FAIL to load the address';
|
93
96
|
_this.evaluateJavascriptOnPage();
|
@@ -97,20 +100,27 @@ surrender.run = function() {
|
|
97
100
|
phantom.exit(1);
|
98
101
|
}
|
99
102
|
|
100
|
-
page.onError = function(
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
page.onError = function(message, trace) {
|
104
|
+
_this.logError(message);
|
105
|
+
|
106
|
+
//if (trace && trace.length) {
|
107
|
+
// msgStack.push('TRACE:');
|
108
|
+
// trace.forEach(function(t) {
|
109
|
+
// msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
|
110
|
+
// });
|
111
|
+
//}
|
108
112
|
// console.log(msgStack.join('\n'));
|
109
113
|
};
|
110
114
|
|
111
|
-
page.onConsoleMessage = function(
|
112
|
-
|
115
|
+
page.onConsoleMessage = function(message, lineNum, sourceId) {
|
116
|
+
_this.logInfo('CONSOLE: ' + message + '(' + sourceId + '/L#"' + lineNum + '")');
|
113
117
|
};
|
118
|
+
|
119
|
+
page.onResourceTimeout = function(request) {
|
120
|
+
console.log('<html><head><meta name="robots" content="noindex, noarchive" /></head><body></body></html>');
|
121
|
+
_this.logWarning('Response (#' + request.id + '): ' + JSON.stringify(request));
|
122
|
+
setTimeout(function() { phantom.exit(1); }, 0); // workaround to avoid PhantomJS crashes
|
123
|
+
}
|
114
124
|
};
|
115
125
|
|
116
126
|
surrender.removeEscapedFragmentParameter = function (addressUrl) {
|
@@ -130,4 +140,35 @@ surrender.removeEscapedFragmentParameter = function (addressUrl) {
|
|
130
140
|
return newUrl;
|
131
141
|
};
|
132
142
|
|
143
|
+
surrender.logFilePath = function() {
|
144
|
+
if (fs.exists("/opt/sites/frontend/current/log"))
|
145
|
+
return "/opt/sites/frontend/current/log";
|
146
|
+
else
|
147
|
+
return "/tmp";
|
148
|
+
};
|
149
|
+
|
150
|
+
surrender.flog = function(message) {
|
151
|
+
try {
|
152
|
+
fs.write(this.logFilePath() + '/etalia-prerender.log', message + "\n", 'a');
|
153
|
+
} catch(e) {
|
154
|
+
// can't fallback on anything
|
155
|
+
}
|
156
|
+
};
|
157
|
+
surrender.logDebug = function(message) {
|
158
|
+
this.flog(this.timestamp() + ' [DEBUG] ' + message);
|
159
|
+
};
|
160
|
+
surrender.logInfo = function(message) {
|
161
|
+
this.flog(this.timestamp() + ' [INFO ] ' + message);
|
162
|
+
};
|
163
|
+
surrender.logWarning = function(message) {
|
164
|
+
this.flog(this.timestamp() + ' [WARN ] ' + message);
|
165
|
+
};
|
166
|
+
surrender.logError = function(message) {
|
167
|
+
this.flog(this.timestamp() + ' [ERROR] ' + message);
|
168
|
+
};
|
169
|
+
|
170
|
+
surrender.timestamp = function() {
|
171
|
+
return new Date().toString().substring(0,24);
|
172
|
+
};
|
173
|
+
|
133
174
|
surrender.run();
|
@@ -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.4'
|
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.4
|
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-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|