Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Last active August 29, 2015 14:01
Show Gist options
  • Save guilleiguaran/6a007e48347f672867b8 to your computer and use it in GitHub Desktop.
Save guilleiguaran/6a007e48347f672867b8 to your computer and use it in GitHub Desktop.
class CountryChecker
COUNTRY_DB = nil # FIX
def initialize(app, options = {})
@app = app
@ip_override = options[:allow_ip_override]
end
def call(env)
request = Rack::Request.new(env)
ip = @ip_override ? request.params['ip'] : request.ip
country = COUNTRY_DB.country(ip).country
if valid_domain?(country)
redirect_to_domain(country)
else
@app.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment