Created
February 1, 2009 16:47
-
-
Save sinatra/55898 to your computer and use it in GitHub Desktop.
This file contains 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
# This method is heavily adapted from the Rails method of determining the subdomain. | |
require 'rubygems' | |
require 'sinatra' | |
helpers do | |
def subdomains(tld_len=1) # we set tld_len to 1, use 2 for co.uk or similar | |
@subdomains ||= if (request.host.nil? || | |
/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(request.host)) | |
request.host.split('.')[0...(1 - tld_len - 2)] | |
else | |
[] | |
end | |
end | |
end | |
get '/' do | |
subdomains.join("<br/>") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment