mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Add custom domains (#314)
This commit is contained in:
committed by
GitHub
parent
d47c70f576
commit
d17b45c5c4
@@ -28,10 +28,44 @@ module ApplicationHelper
|
||||
end
|
||||
end
|
||||
|
||||
def add_subdomain_to(url_helper, resource=nil, options={})
|
||||
options[:subdomain] = Current.tenant_or_raise!.subdomain if Rails.application.multi_tenancy?
|
||||
options[:host] = Rails.application.base_url
|
||||
def get_url_for(url_helper, resource: nil, disallow_custom_domain: false, options: {})
|
||||
custom_domain = Current.tenant.custom_domain
|
||||
|
||||
if Rails.application.multi_tenancy? && (custom_domain.blank? || disallow_custom_domain)
|
||||
options[:subdomain] = Current.tenant.subdomain
|
||||
end
|
||||
|
||||
if custom_domain.blank? || disallow_custom_domain
|
||||
options[:host] = Rails.application.base_url
|
||||
else
|
||||
options[:host] = custom_domain
|
||||
end
|
||||
|
||||
if Rails.application.base_url.include?('https')
|
||||
options[:protocol] = 'https'
|
||||
else
|
||||
options[:protocol] = 'http'
|
||||
end
|
||||
|
||||
resource ? url_helper.call(resource, options) : url_helper.call(options)
|
||||
end
|
||||
|
||||
def get_tenant_from_request(request)
|
||||
if Rails.application.multi_tenancy?
|
||||
request_host_splitted = request.host.split('.')
|
||||
app_host_splitted = URI.parse(Rails.application.base_url).host.split('.')
|
||||
|
||||
if app_host_splitted.join('.') == request_host_splitted.last(app_host_splitted.length).join('.')
|
||||
return if request.subdomain.blank? or RESERVED_SUBDOMAINS.include?(request.subdomain)
|
||||
|
||||
tenant = Tenant.find_by(subdomain: request.subdomain)
|
||||
else
|
||||
tenant = Tenant.find_by(custom_domain: request.host)
|
||||
end
|
||||
else
|
||||
tenant = Tenant.first
|
||||
end
|
||||
|
||||
tenant
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user