Class: Hippo::API::TenantDomainRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/hippo/api/tenant_domain_router.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ TenantDomainRouter

Returns a new instance of TenantDomainRouter.


4
5
6
# File 'lib/hippo/api/tenant_domain_router.rb', line 4

def initialize(app)
    @app = app
end

Instance Method Details

#call(env) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/hippo/api/tenant_domain_router.rb', line 8

def call(env)
    domain_parts = env['SERVER_NAME'].split('.')
    if domain_parts.length == 3
        tenant = Hippo::Tenant.where(slug: domain_parts.first).first
        MultiTenant.with(tenant) do
            @app.call(env)
        end
    else
        @app.call(env)
    end
end