Class: Houser::Middleware

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Middleware.



5
6
7
8
9
10
# File 'lib/houser/middleware.rb', line 5

def initialize(app, options={})
  @options = options
  @options[:class_name] = Object.const_get(@options[:class_name])
  @options[:tld_length] ||= 1
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/houser/middleware.rb', line 12

def call(env)
  domain_parts = env['HTTP_HOST'].split('.')

  if domain_parts.length > 1 + @options[:tld_length]
    subdomain = domain_parts[0]
    find_tenant(env, subdomain)
  end

  @app.call(env)
end