Skip to content

Instantly share code, notes, and snippets.

@misza222
Created January 12, 2010 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misza222/275105 to your computer and use it in GitHub Desktop.
Save misza222/275105 to your computer and use it in GitHub Desktop.
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