prerender_rails_embedded 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +1 -0
- data/README.md +99 -1
- data/lib/prerender_rails_embedded.rb +1 -1
- data/prerender_rails_embedded.gemspec +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzU2Y2U3YWRmMTViMjMxMzFlMzc1ZmMzMGQ3NWVjN2Q5ZTllMjcxNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzE3NGZmOWQxMGUwMWYxMDAwMmU2ZTViMzk4ZmQwZjc4MGM4OTQyZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWE3ZTU2NGU0NjcxOWQyMmM2MTBlN2FkYmFkNmNmZDYwMmU3MjQ1ODAyMWYx
|
10
|
+
ZDBlN2QwMmVhYWUyNjU3OWYyZTc5MDhlOTdhZGQwMTg0NzNkMjc2YTdkZDY0
|
11
|
+
MjE2M2QyYTJhOGQyNDQ1N2YyNGNmMWI0MWUwMTA0MjE4NDY0NTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTEzZDExYjAzMDc0NTIxYzZkM2U4MGU5OGYzYjY1MzQ2YzJiN2YyYjBjM2Ix
|
14
|
+
ZmE3MzNlODVkZWM2NmQwZDgyMDA0MDU1MDk2OTU3YWI3YTZkYmQxNjFkOTk4
|
15
|
+
MjI4YTUzMDkzYTVjMjM5NzMzNjI0MmU0ZjRkYjNmNTBjNTU5OWU=
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1 +1,99 @@
|
|
1
|
-
|
1
|
+
Prerender Rails Embedded
|
2
|
+
========================
|
3
|
+
A rails gem to use [prerender_rails](https://github.com/prerender/prerender_rails) middleware
|
4
|
+
to render JavaScript web app calling phantomjs on the fly without installing other services.
|
5
|
+
|
6
|
+
### <a id='middleware'></a>
|
7
|
+
## Overview
|
8
|
+
|
9
|
+
With **Prerender Rails Embedded** can be avoided a new node.js server installation in a
|
10
|
+
rails environment because rails will launch a `phantomjs` binary to render the js page.
|
11
|
+
|
12
|
+
Just to try out the [prerender.io/server](https://prerender.io/server) technology
|
13
|
+
and for low traffic situation, this plugin is not meant to support heavy traffic loads.
|
14
|
+
|
15
|
+
### <a id='installation'></a>
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add in your `Gemfile` a line with
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'prerender_rails_embedded'
|
22
|
+
```
|
23
|
+
|
24
|
+
and launch a
|
25
|
+
|
26
|
+
bundle install
|
27
|
+
|
28
|
+
to install it. Then in the `config/environment/production.rb` it should be added:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
config.middleware.use Rack::Prerender before_render: PrerenderRailsEmbedded.local_renderer
|
32
|
+
```
|
33
|
+
|
34
|
+
### <a id='test'></a>
|
35
|
+
### Test
|
36
|
+
|
37
|
+
To test the correct functioning of the `prerender_rails_embedded` gem just start rails
|
38
|
+
with `rails s` and launch a curl to a (js generated) url like this:
|
39
|
+
|
40
|
+
curl -H "User-Agent: Mozilla/5.0 baiduspider" \
|
41
|
+
"http://localhost:4000/articles/a0af82a84-d386-4690-9f68-81ac768bc6d3"
|
42
|
+
|
43
|
+
It should show a completely rendered page in standard output.
|
44
|
+
|
45
|
+
### Warning
|
46
|
+
|
47
|
+
**WEBrick** and **Thin** don't support multiple nested requests so, using them it will
|
48
|
+
hang the request until a timeout is issued by the web server. To test it out you should
|
49
|
+
consider using [unicorn](http://unicorn.bogomips.org/) with more than one worker thread.
|
50
|
+
|
51
|
+
Just add `gen unicorn` to your `Gemfile` launch `bundle install` create a `config/unicorn.rb`
|
52
|
+
file with content (adjusting it to your needs)
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
# config/unicorn.rb
|
56
|
+
worker_processes 3
|
57
|
+
timeout 30
|
58
|
+
preload_app true
|
59
|
+
|
60
|
+
before_fork do |server, worker|
|
61
|
+
|
62
|
+
Signal.trap 'TERM' do
|
63
|
+
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
|
64
|
+
Process.kill 'QUIT', Process.pid
|
65
|
+
end
|
66
|
+
|
67
|
+
defined?(ActiveRecord::Base) and
|
68
|
+
ActiveRecord::Base.connection.disconnect!
|
69
|
+
end
|
70
|
+
|
71
|
+
after_fork do |server, worker|
|
72
|
+
|
73
|
+
Signal.trap 'TERM' do
|
74
|
+
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
|
75
|
+
end
|
76
|
+
|
77
|
+
defined?(ActiveRecord::Base) and
|
78
|
+
ActiveRecord::Base.establish_connection
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
and launch the web server with the command:
|
83
|
+
|
84
|
+
```shell
|
85
|
+
bundle exec unicorn -p 3000 -c ./config/unicorn.rb
|
86
|
+
```
|
87
|
+
|
88
|
+
### <a id='todos'></a>
|
89
|
+
## TODOs
|
90
|
+
|
91
|
+
This has been a very quick development so there are
|
92
|
+
|
93
|
+
* exceptions should exit immediately from phantomjs and in some cases they DON'T
|
94
|
+
* add a timeout for too long phantojs processing
|
95
|
+
* support 404 and error code in the same way prerender.io (server) does
|
96
|
+
|
97
|
+
### Future enhancements
|
98
|
+
* add memory/disk cache deciding a correct eviction policy to avoid rendering pages
|
99
|
+
multiple times.
|
@@ -2,7 +2,7 @@ module PrerenderRailsEmbedded
|
|
2
2
|
require 'phantomjs'
|
3
3
|
|
4
4
|
def self.flatten_js_to_html(url)
|
5
|
-
Phantomjs.run(
|
5
|
+
Phantomjs.run('--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
6
|
end
|
7
7
|
|
8
8
|
def self.local_renderer
|
@@ -1,19 +1,19 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
5
|
-
spec.version =
|
6
|
-
spec.authors = [
|
7
|
-
spec.email =
|
4
|
+
spec.name = 'prerender_rails_embedded'
|
5
|
+
spec.version = '0.1.1'
|
6
|
+
spec.authors = ['Gian Carlo Pace']
|
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}
|
9
9
|
spec.summary = %q{Prerender your backbone/angular/javascript rendered application on the fly when search engines crawl}
|
10
|
-
spec.homepage =
|
11
|
-
spec.license =
|
10
|
+
spec.homepage = 'https://github.com/EtaliaSA/prerender_rails_embedded'
|
11
|
+
spec.license = 'Apache License 2.0'
|
12
12
|
|
13
13
|
spec.files = `git ls-files`.split($/)
|
14
14
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
-
spec.require_paths =
|
16
|
+
spec.require_paths = %w(lib)
|
17
17
|
|
18
18
|
spec.add_development_dependency "bundler", "~> 1.3"
|
19
19
|
spec.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prerender_rails_embedded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gian Carlo Pace
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|