class AssetServer

Attributes

app[R]
res[R]

Public Class Methods

new(app) click to toggle source
# File lib/laris/asset_server.rb, line 4
def initialize(app)
  @app = app
  @res = Rack::Response.new
end

Public Instance Methods

call(env) click to toggle source
# File lib/laris/asset_server.rb, line 9
def call(env)
  req = Rack::Request.new(env)
  if req.path =~ (/^\/assets/)
    respond_with_asset(req)
  else
    app.call(env)
  end
end

Private Instance Methods

respond_with_asset(req) click to toggle source
# File lib/laris/asset_server.rb, line 19
def respond_with_asset(req)
  dir_path = File.dirname(__FILE__)
  path = File.join(Laris::ROOT, "app", req.path)

  ext = File.extname(path)
  ext = ".json" if ext == ".map"
  res["Content-Type"] = Rack::Mime::MIME_TYPES[ext]

  res.write(File.read(path))
  res.finish
end