Class: Rack::WildCardSubdomains

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ WildCardSubdomains

Returns a new instance of WildCardSubdomains.



3
4
5
# File 'lib/rack/wildcard_subdomains.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  #Lets leave it alone if we're in development
  return @app.call(env) if env["HTTP_HOST"] =~ /127\.0\.0\.1/

  #Move along, nothing to see here, subdomain we should ignore
  subdomain = nil
  matches = env["HTTP_HOST"].match(/([^\.]*)\..+\..+/)
  #Keep going if there isn't a subdomain
  if matches.nil?
    Rails.logger.warn "*** Submariner - No subdomain detected"
    return @app.call(env) unless matches
  end
  subdomain = matches[1]

  if Submariner::WildCardSubdomain.subdomains_to_ignore.include?(subdomain)
    Rails.logger.warn "*** Submariner - skipped domain #{subdomain} based on configuration"
    return @app.call(env)
  end
    Rails.logger.warn "*** Submariner - detected domain #{subdomain}"
    Submariner::WildCardSubdomain.subdomain_block.call(subdomain)
  @app.call(env)
end