Created
June 24, 2014 09:24
-
-
Save guillermo/15b20b598d6965bb1646 to your computer and use it in GitHub Desktop.
Rack Middleware for filtering domains
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
class DomainFilter | |
def initialize(app, domain, &block) | |
@external_app = app | |
@domain_app = Rack::Builder.new(&block) | |
@domain = domain | |
end | |
def call(env) | |
if env["HTTP_HOST"].match(@domain) | |
@domain_app.call(env) | |
else | |
@external_app.call(env) | |
end | |
end | |
end | |
# use DomainFilter, /\Amy\.domain\.com\z/ do | |
# run MySinatraApp | |
# end | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment