Created
October 8, 2008 11:29
-
-
Save speedmax/15495 to your computer and use it in GitHub Desktop.
cname lookup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :load_site | |
private | |
def load_site | |
if request.host =~ Site.domain_pattern | |
subdomain = current_subdomain | |
else | |
subdomain = find_cname(request.host) | |
end | |
@site ||= Site.find_by_subdomain(subdomain) | |
render :text => 'Site not found' unless @site | |
end | |
def find_cname(host) | |
Rails.cache.fetch("dns_map:#{host}") { | |
Net::DNS::Resolver.new.query(host).each_cname do |cname| | |
return $1 if cname.match Site.domain_pattern | |
end | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment