Sha256: 0abf71f884ca25406fd41b6b523f97c1de61d0dcc64ddb40f2d8a5a32dfb836a
Contents?: true
Size: 919 Bytes
Versions: 11
Compression:
Stored size: 919 Bytes
Contents
# Allow the metal piece to run in isolation require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) # Serves theme files from the theme directory without touching Rails too much class ThemeServer def initialize(app) @app = app end def call(env) if env["PATH_INFO"] =~ /^\/theme/ and (theme = Theme.current_theme(env)).present? env["PATH_INFO"].gsub!(/^\/theme\//, '') if (file_path = (dir = Rails.root.join("themes", theme)).join(env["PATH_INFO"])).exist? etag = Digest::MD5.hexdigest("#{file_path.to_s}#{file_path.mtime}") unless (etag == env["HTTP_IF_NONE_MATCH"]) status, headers, body = Rack::File.new(dir).call(env) [status, headers.update({"ETag" => etag}), body] else [304, {"ETag" => etag}, []] end else [404, {}, []] end else @app.call(env) end end end
Version data entries
11 entries across 11 versions & 1 rubygems