Created
January 12, 2010 10:41
-
-
Save misza222/275105 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
module Rack | |
# Redirects to correct domain | |
class RedirectToDomain | |
HOST = 'example.com' | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
req = Rack::Request.new(env) | |
# localhost for local development | |
if req.host == HOST or req.host == 'localhost' | |
@app.call(env) | |
else | |
res = Rack::Response.new | |
res.redirect("http://#{HOST}/") | |
res.finish | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment