lib/conjur/webserver/home.rb in conjur-asset-ui-api-1.1.1 vs lib/conjur/webserver/home.rb in conjur-asset-ui-api-1.2.0
- old
+ new
@@ -1,36 +1,42 @@
require 'time'
require 'rack/utils'
require 'rack/mime'
+require 'conjur/webserver/renderer'
+
module Conjur
module WebServer
class Home
- F = ::File
-
def initialize(root)
@root = root
end
-
+
# From Rack::File
def call(env)
- path = File.expand_path("index.html", @root)
+ path = File.expand_path(INDEX, @root)
+ renderer = Renderer.new @root
- if env["REQUEST_METHOD"] == "OPTIONS"
- return [200, {'Allow' => ALLOW_HEADER, 'Content-Length' => '0'}, []]
- end
- last_modified = F.mtime(path).httpdate
+ page = renderer.render File.read(path)
+ files = renderer.files + [path]
+
+ last_modified = files.map(&File.method(:mtime)).max.httpdate
+
return [304, {}, []] if env['HTTP_IF_MODIFIED_SINCE'] == last_modified
- size = F.size?(path) || Rack::Utils.bytesize(F.read(path))
-
- headers = {
+ size = Rack::Utils.bytesize(page)
+
+ headers = {
"Last-Modified" => last_modified,
"Content-Type" => "text/html",
"Content-Length" => size.to_s
}
-
- [ 200, headers, env["REQUEST_METHOD"] == "HEAD" ? [] : [ F.read(path) ] ]
+
+ [200, headers, env["REQUEST_METHOD"] == "HEAD" ? [] : [page]]
end
+
+ private
+
+ INDEX = 'index.html.erb'.freeze
end
end
end