Websites/config/routes/domain_constraint.rb
Donovan Daniels b1c702e3cd
Add image management ui
poorly tested but it worked well enough, I'm sure I'll be patching bugs over the next few weeks
Also remove turbo because it sucks
Also changed the way we handle hosts in dev
2024-05-06 03:25:17 -05:00

36 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class DomainConstraint
attr_reader :domain, :subdomain
DEFAULT_DOMAIN = nil # "yiff.rest"
def initialize(domain, subdomain = nil)
@domain = domain
@subdomain = subdomain
end
def matches?(request)
if Rails.env.development?
domain = request.env["websites.dev_domain"].presence || request.domain
subdomains = request.env["websites.dev_subdomains"].presence || request.subdomains
Rails.logger.info("Domain: #{@domain}; Subdomain: #{@subdomain}; Current Host: #{domain}; Current Subdomains: #{subdomains}; Matches (Domain): #{domain_matches?(request)}; Matches (Subdomain): #{subdomain_matches?(request)}")
end
subdomain_matches?(request) && domain_matches?(request)
end
private
def domain_matches?(request)
(Rails.env.development? && request.env["websites.dev_domain"] == @domain) || request.domain == @domain
end
def subdomain_matches?(request)
if Rails.env.development? && !request.env["websites.dev_subdomains"].nil?
return true if @subdomain.nil? && request.env["websites.dev_subdomains"].blank?
return true if request.env["websites.dev_subdomains"] == @subdomain
end
(@subdomain.nil? && request.subdomain.blank?) || request.subdomain == @subdomain
end
end