Class: Bezel::StaticAssets

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ StaticAssets

Returns a new instance of StaticAssets.



3
4
5
# File 'lib/static_assets.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/static_assets.rb', line 7

def call(env)
  file_path = "." + env['PATH_INFO']
  if file_path =~ (/app\/assets/)
    res = Rack::Response.new
    extension = File.extname(file_path)
      begin
        extension = ".json" if extension == ".map"
        res["Content-Type"] = Rack::Mime::MIME_TYPES[extension]
        content = File.read(file_path)
        res.write(content)
      rescue
        res.status = 404
      end
      res.finish
  else
    @app.call(env)
  end
end