phrender 0.0.2 → 0.0.3
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 +4 -4
- data/lib/phrender/rack_middleware.rb +32 -14
- data/lib/phrender/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c071fb71537894c6506cda8fdf3107307aff153
|
4
|
+
data.tar.gz: 1db4ff01dbba039dd67fce848435dfbfc82c8f9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6706612f43d4d98a2eca5f8d5479aef880a933cd90a03b2309ad251c52896afbf3e4e1e4aef6730a9edea83fe8e312ab817a74bb4aadefdbe9f679d0710802e4
|
7
|
+
data.tar.gz: 7d7d8093472e1b8d49a6be861a900458072129fae8789672f2f13056ccb334ef35ec178ce5a23f1a7a17339412c28d5994934548a576df4b5ed0cd5240fe5933
|
@@ -12,13 +12,23 @@ class Phrender::RackMiddleware
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def call(env)
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
@req = Rack::Request.new(env)
|
16
|
+
|
17
|
+
# Check if the next middleware can handle the request
|
18
|
+
status, headers, body = @app.call(@req.env)
|
19
|
+
|
20
|
+
# If it can't, or if it's just the index file delivered via aliasing for
|
21
|
+
# pushstate, do phrender stuff.
|
22
|
+
if (status == 404 || headers['Push-State-Redirect'])
|
23
|
+
# If it's phantom making the request, then the phrender index file has
|
24
|
+
# a request that the upstream server can't resolve, so catch it, instead
|
25
|
+
# of recursively invoking the index
|
26
|
+
if (@req.user_agent.match(/PhantomJS/))
|
18
27
|
[ 500, { 'Content-Type' => 'text/html' }, [
|
19
28
|
'Server Error: HTML file contains recursive lookup' ] ]
|
20
29
|
else
|
21
|
-
|
30
|
+
# Render the page
|
31
|
+
body = render(@req.url)
|
22
32
|
[ 200, { 'Content-Type' => 'text/html' }, [ body ] ]
|
23
33
|
end
|
24
34
|
else
|
@@ -35,11 +45,16 @@ class Phrender::RackMiddleware
|
|
35
45
|
end
|
36
46
|
|
37
47
|
def load_html
|
38
|
-
req =
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
48
|
+
req = @req.dup
|
49
|
+
req.path_info = @index_file
|
50
|
+
|
51
|
+
# Attach a param to indicate that it's phrender requesting the page. This is
|
52
|
+
# only useful if the index file is delivered via a dynamic backend. Ignored
|
53
|
+
# otherwise.
|
54
|
+
req.update_param('phrender', true)
|
55
|
+
req.env['REQUEST_METHOD'] = 'GET'
|
56
|
+
|
57
|
+
status, headers, body = @app.call(req.env)
|
43
58
|
parse_body body
|
44
59
|
end
|
45
60
|
|
@@ -48,11 +63,11 @@ class Phrender::RackMiddleware
|
|
48
63
|
if path == :ember_driver
|
49
64
|
Phrender::EMBER_DRIVER
|
50
65
|
else
|
51
|
-
req =
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
status, headers, body = @app.call(req)
|
66
|
+
req = @req.dup
|
67
|
+
req.path_info = path
|
68
|
+
req.env['REQUEST_METHOD'] = 'GET'
|
69
|
+
|
70
|
+
status, headers, body = @app.call(req.env)
|
56
71
|
parse_body body
|
57
72
|
end
|
58
73
|
end.join(';')
|
@@ -61,6 +76,9 @@ class Phrender::RackMiddleware
|
|
61
76
|
end
|
62
77
|
|
63
78
|
def parse_body(body)
|
79
|
+
# Rack responses must respond to each, which is generally a polyfil that
|
80
|
+
# yields the response, so reassemble it here, or just treat it like a
|
81
|
+
# string.
|
64
82
|
if body.respond_to? :each
|
65
83
|
data = ''
|
66
84
|
body.each{ |part| data << part }
|
data/lib/phrender/version.rb
CHANGED