Class: Rack::Rewritten::Subdomain
- Inherits:
-
Object
- Object
- Rack::Rewritten::Subdomain
- Defined in:
- lib/rack/subdomain.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, *fqdns) ⇒ Subdomain
constructor
A new instance of Subdomain.
Constructor Details
#initialize(app, *fqdns) ⇒ Subdomain
Returns a new instance of Subdomain.
9 10 11 12 |
# File 'lib/rack/subdomain.rb', line 9 def initialize(app, *fqdns) @app = app @fqdns = fqdns end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/subdomain.rb', line 14 def call(env) puts "-> Rack::Rewritten::Subdomain" req = Rack::Request.new(env) @fqdns.each do |n| if req.host =~ /(.+)\.#{n}$/ if $1 == 'www' break else env["SUBDOMAIN"] = $1 env["FQDN"] = n break end end end @app.call(env) end |