Class: RestPack::Web::App

Inherits:
Object
  • Object
show all
Defined in:
lib/restpack-web/app.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ App

Returns a new instance of App.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/restpack-web/app.rb', line 6

def initialize(app, options = {})
  p "RestPack::Web::App.initialize"
  @app = app

  options[:core_domain] ||= ENV['RESTPACK_CORE_SERVICE']
  options[:access_key] ||= ENV['RESTPACK_ACCESS_KEY']
  
  p "RestPack::Web::App.initialize: core_domain #{options[:core_domain]}"
  @options = options
  
  unless options[:core_domain] || options[:access_key]
    p "[WARNING] Missing RestPack configuration"
  else
    @core_cache = RestPack::Core::Client::Cache.create(options[:core_domain], options[:access_key])
  end
end

Instance Method Details

#call(env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/restpack-web/app.rb', line 23

def call(env)
  env[:restpack] ||= {}

  #TODO: GJ: ignore requests with a file extension
  request = Rack::Request.new(env)
  channel = @core_cache.get_channel(request.host)
  domain = channel.get_domain_by_host(request.host)
  
  env[:restpack][:request] = request
  env[:restpack][:host] = request.host
  env[:restpack][:channel] = channel
  env[:restpack][:application] = domain.application
  env[:restpack][:domain] = domain
  env[:restpack][:configurations] = @core_cache.configurations
  env[:restpack][:services] = @core_cache.get_configuration_value('services', [])
  
  add_user env

  @app.call(env)
end