Class: SiteDetector
- Inherits:
-
Object
- Object
- SiteDetector
- Defined in:
- lib/yodel/middleware/site_detector.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ SiteDetector
constructor
A new instance of SiteDetector.
Constructor Details
#initialize(app) ⇒ SiteDetector
Returns a new instance of SiteDetector.
2 3 4 |
# File 'lib/yodel/middleware/site_detector.rb', line 2 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/yodel/middleware/site_detector.rb', line 6 def call(env) request = Rack::Request.new(env) site = Site.where(domains: request.host).first env['yodel.site'] = site unless site.nil? if Yodel.env.production? raise MissingRootDirectory.new(site, request.port) if !File.directory?(site.root_directory) env['rack.session.options'][:domain] = ".#{site.domains.first}" end else raise DomainNotFound.new(request.host, request.port) if Yodel.env.production? end @app.call(env) end |