Class: Rack::Domain
- Inherits:
-
Object
- Object
- Rack::Domain
- Defined in:
- lib/rack/domain.rb,
lib/rack/domain/version.rb
Overview
This Rack middleware allows to intercept requests and route them to different apps based on the domain (full, with subdomains and the TLD).
Constant Summary collapse
- VERSION =
The version of this gem.
'1.0.0'
Instance Method Summary collapse
-
#call(env) ⇒ Object
The
call
method as per the Rack middleware specification. -
#initialize(next_app, filter, opts = {}, &block) ⇒ Domain
constructor
Create a new instance of this middleware.
Constructor Details
#initialize(next_app, filter, opts = {}, &block) ⇒ Domain
Create a new instance of this middleware.
Note that this method is the method called by Rack::Builder#use
.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rack/domain.rb', line 41 def initialize(next_app, filter, opts = {}, &block) if opts[:run] && block_given? fail ArgumentError, 'Pass either an app to run or a block, not both' end @next_app = next_app @filter = filter @app_to_run = opts[:run] @dsl_block = block end |
Instance Method Details
#call(env) ⇒ Object
The call
method as per the Rack middleware specification.
54 55 56 57 58 |
# File 'lib/rack/domain.rb', line 54 def call(env) @domain = Rack::Request.new(env).host app = domain_matches? ? app_or_dsl_block : @next_app app.call(env) end |