Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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