Class: Locomotive::Middlewares::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/middlewares/site.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ Site

Returns a new instance of Site.



5
6
7
# File 'lib/locomotive/middlewares/site.rb', line 5

def initialize(app, opts = {})
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
# File 'lib/locomotive/middlewares/site.rb', line 9

def call(env)
  env['locomotive.site'] = fetch_site(env)
  @app.call(env)
end

#fetch_site(env) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/locomotive/middlewares/site.rb', line 14

def fetch_site(env)
  request = Rack::Request.new(env)
  Locomotive.log "[fetch site] host = #{request.host} / #{env['HTTP_HOST']}"
  if Locomotive.config.multi_sites?
    Locomotive::Site.match_domain(request.host).first
  else
    Locomotive::Site.first
  end
end