Class: Webhookdb::Webterm::ServeIndexHtmlFromRoot

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ServeIndexHtmlFromRoot

Returns a new instance of ServeIndexHtmlFromRoot.



30
31
32
33
# File 'lib/webterm/apps.rb', line 30

def initialize(app)
  @app = app
  @cached_html = nil
end

Instance Method Details

#call(env) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/webterm/apps.rb', line 35

def call(env)
  return @app.call(env) unless env[Rack::PATH_INFO] == "/"
  if @cached_html.nil?
    html = File.read(File.join(STATIC, "index.html"))
    html.sub!("/* REPLACE_WHDB_ENV */", "window.whdbEnv = [['WEBHOOKDB_API_HOST', '#{Webhookdb.api_url}']]")
    @cached_html = html.chars
  end
  return [200, {"Content-Type" => "text/html"}, @cached_html]
end