module Rack
class Request
def subdomains
@env['rack.env.subdomains'] ||= lambda {
return [] if (host.nil? ||
/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
host.split('.')[0...-2]
}.call
end
end
end
before do
@purl_base = if request.subdomains.empty? then request.host else request.host.sub("#{request.subdomains.join('.')}.", "") end #personalurl.com
@purl = Purl.first(:purl => @purl_base)
Purl.current = @purl
@user = CData.first(:unique_name => request.subdomains.join('.')) unless request.subdomains.empty? #g.manley
end
get '/' do
if
request.subdomains.empty?
then
erb :"#{@purl.name}/blank"
else
erb :"#{@purl.name}/index"
end
end
Refactorings
No refactoring yet !
mikhailov
April 27, 2010, April 27, 2010 11:39, permalink
I usually use of third-level domains, so this my version of codesource
module Rack
class Request
def subdomain
sub = host.present? && host.split('.')[0...-2]
sub.one? && sub.first || nil
end
end
end
class ApiVersion1 < Sinatra::Application
get '/api/v1/company.xml' do
company = Company.find_by_subdomain(request.subdomain)
headers 'Content-Type' => 'text/xml'
company.to_xml
end
end
mikhailov
April 27, 2010, April 27, 2010 11:41, permalink
I usually use of third-level domains, so this my version of codesource
module Rack
class Request
def subdomain
sub = host.present? && host.split('.')[0...-2]
sub.one? && sub.first || nil
end
end
end
class ApiVersion1 < Sinatra::Application
get '/api/v1/company.xml' do
company = Company.find_by_subdomain(request.subdomain)
headers 'Content-Type' => 'text/xml'
company.to_xml
end
end
Chinese Zodiac
October 16, 2010, October 16, 2010 02:55, permalink
"How-do-you-do, just needed you to learn We've extra your internet site to my Yahoo bookmarks because of your remarkable weblog layout. But severely, I assume your internet site has a single of the freshest theme I've came across. It genuinely helps make studying your blog a great deal simpler."
harley davidson
November 2, 2010, November 02, 2010 06:04, permalink
The man who has made up his mind to win will never say "impossible ".
So i need to define @purl_base and @user. @user needs to be defined only if the url navigated to has a subdomain (g.manley.personalurl.com). @purl_base is currently being defined by sub'ing out the subdomain but if there is no subdomain then obviously it doesn't need to be subbed out. I currently have a semi working version of it but its pretty clunky and wanted to see if there was a better way like maybe even a rack function that i missed that defines the base url.
Its a sinatra app using datamapper.