Class: Propshaft::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/propshaft/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(assembly) ⇒ Server

Returns a new instance of Server.



4
5
6
# File 'lib/propshaft/server.rb', line 4

def initialize(assembly)
  @assembly = assembly
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/propshaft/server.rb', line 8

def call(env)
  path, digest = extract_path_and_digest(env)

  if (asset = @assembly.load_path.find(path)) && asset.fresh?(digest)
    compiled_content = @assembly.compilers.compile(asset)

    [ 
      200, 
      {
        "Content-Length"  => compiled_content.length.to_s,
        "Content-Type"    => asset.content_type.to_s,
        "Accept-Encoding" => "Vary",
        "ETag"            => asset.digest,
        "Cache-Control"   => "public, max-age=31536000, immutable"
      },
      [ compiled_content ]
    ]
  else
    [ 404, { "Content-Type" => "text/plain", "Content-Length" => "9" }, [ "Not found" ] ]
  end
end