Skip to content

Instantly share code, notes, and snippets.

@nathany
Created October 12, 2009 00:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nathany/207983 to your computer and use it in GitHub Desktop.
Save nathany/207983 to your computer and use it in GitHub Desktop.
Heroku is great to host single-page "sites" for all those domains I'm not using.
require 'rubygems'
require 'sinatra'
require 'haml'
Domains = %w{gemsmith vogsphere youngman seraph intercessory cyaonline significantwhitespace 14159265358979}
DefaultDomain = 'default'
# what domain does the host contain?
# put this here because helpers are a pain to test!
def view_for_domain(host)
return DefaultDomain if host.nil?
Domains.find do |domain|
host.include?(domain)
end || DefaultDomain
end
def view_exists?(view)
File.exists?(Dir.pwd + "/views/#{view}.haml")
end
# the catch-all route
get '/*' do
# parse domain
@view = view_for_domain(request.env["HTTP_HOST"])
# override with text anywhere in url (for testing)
splat = params['splat'].first
if(@view == DefaultDomain && !splat.empty?) then
@view = view_for_domain(splat)
end
# ensure view exists, and load
@view = DefaultDomain unless view_exists?(@view)
haml @view.to_sym
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment