Class: Rack::Rewritten::Subdomain

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

Instance Method Summary collapse

Constructor Details

#initialize(app, *fqdns) ⇒ Subdomain

Returns a new instance of Subdomain.



6
7
8
9
# File 'lib/rack/subdomain.rb', line 6

def initialize(app, *fqdns)
  @app = app
  @fqdns = fqdns
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rack/subdomain.rb', line 11

def call(env)
  puts '-> Rack::Rewritten::Subdomain'
  req = Rack::Request.new(env)

  @fqdns.each do |n|
    if req.host =~ /(.+)\.#{n}$/
      if Regexp.last_match(1) == 'www'
        break
      else
        env['SUBDOMAIN'] = Regexp.last_match(1)
        env['FQDN'] = n
        break
      end
    end
  end

  @app.call(env)
end