propshaft 1.2.1 → 1.3.0
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/propshaft/assembly.rb +5 -2
- data/lib/propshaft/railtie.rb +7 -8
- data/lib/propshaft/server.rb +31 -21
- data/lib/propshaft/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88560fd134482bd4d44518bde9a6813be01d538f16409be833e36664a3c998bc
|
4
|
+
data.tar.gz: df495a737f633966e4aa8f7837400353ec2bc9166142e38a94b7d50350c2e092
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f27ba3bd99cbbaeb643f466c8d37051a988809c1415ccdec2eff5577506eeeed8f4c772167e8afe461b349bb4b4e75aa22bedde7c256d023796929296d1c00e1
|
7
|
+
data.tar.gz: 571d8052e3b16c7d779c55433d27c268f0ceb387213ca4b0220a200dc30885e15accc855075e4fbcf95ea71c887ff071bfa25caaa8330f0e9a5c87c33c10076f
|
data/lib/propshaft/assembly.rb
CHANGED
data/lib/propshaft/railtie.rb
CHANGED
@@ -42,14 +42,6 @@ module Propshaft
|
|
42
42
|
Pathname.new(File.join(app.config.paths["public"].first, app.config.assets.prefix))
|
43
43
|
config.assets.manifest_path ||= config.assets.output_path.join(".manifest.json")
|
44
44
|
|
45
|
-
app.assets = Propshaft::Assembly.new(app.config.assets)
|
46
|
-
|
47
|
-
if config.assets.server
|
48
|
-
app.routes.prepend do
|
49
|
-
mount app.assets.server, at: app.assets.config.prefix
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
45
|
ActiveSupport.on_load(:action_view) do
|
54
46
|
include Propshaft::Helper
|
55
47
|
end
|
@@ -71,6 +63,13 @@ module Propshaft
|
|
71
63
|
end
|
72
64
|
end
|
73
65
|
|
66
|
+
initializer "propshaft.assets_middleware", group: :all do |app|
|
67
|
+
app.assets = Propshaft::Assembly.new(app.config.assets)
|
68
|
+
if config.assets.server
|
69
|
+
app.middleware.insert_after ::ActionDispatch::Static, Propshaft::Server, app.assets
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
74
73
|
rake_tasks do
|
75
74
|
load "propshaft/railties/assets.rake"
|
76
75
|
end
|
data/lib/propshaft/server.rb
CHANGED
@@ -2,30 +2,39 @@ require "rack/utils"
|
|
2
2
|
require "rack/version"
|
3
3
|
|
4
4
|
class Propshaft::Server
|
5
|
-
def initialize(assembly)
|
5
|
+
def initialize(app, assembly)
|
6
|
+
@app = app
|
6
7
|
@assembly = assembly
|
7
8
|
end
|
8
9
|
|
9
10
|
def call(env)
|
10
11
|
execute_cache_sweeper_if_updated
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
|
13
|
+
path = env["PATH_INFO"]
|
14
|
+
method = env["REQUEST_METHOD"]
|
15
|
+
|
16
|
+
if (method == "GET" || method == "HEAD") && path.start_with?(@assembly.prefix)
|
17
|
+
path, digest = extract_path_and_digest(path)
|
18
|
+
|
19
|
+
if (asset = @assembly.load_path.find(path)) && asset.fresh?(digest)
|
20
|
+
compiled_content = asset.compiled_content
|
21
|
+
|
22
|
+
[
|
23
|
+
200,
|
24
|
+
{
|
25
|
+
Rack::CONTENT_LENGTH => compiled_content.length.to_s,
|
26
|
+
Rack::CONTENT_TYPE => asset.content_type.to_s,
|
27
|
+
VARY => "Accept-Encoding",
|
28
|
+
Rack::ETAG => "\"#{asset.digest}\"",
|
29
|
+
Rack::CACHE_CONTROL => "public, max-age=31536000, immutable"
|
30
|
+
},
|
31
|
+
method == "HEAD" ? [] : [ compiled_content ]
|
32
|
+
]
|
33
|
+
else
|
34
|
+
[ 404, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "9" }, [ "Not found" ] ]
|
35
|
+
end
|
27
36
|
else
|
28
|
-
|
37
|
+
@app.call(env)
|
29
38
|
end
|
30
39
|
end
|
31
40
|
|
@@ -34,10 +43,11 @@ class Propshaft::Server
|
|
34
43
|
end
|
35
44
|
|
36
45
|
private
|
37
|
-
def extract_path_and_digest(
|
38
|
-
|
46
|
+
def extract_path_and_digest(path)
|
47
|
+
path = path.delete_prefix(@assembly.prefix)
|
48
|
+
path = Rack::Utils.unescape(path)
|
39
49
|
|
40
|
-
Propshaft::Asset.extract_path_and_digest(
|
50
|
+
Propshaft::Asset.extract_path_and_digest(path)
|
41
51
|
end
|
42
52
|
|
43
53
|
if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3")
|
data/lib/propshaft/version.rb
CHANGED