0

需要针对基于国家/地区的检查的 chaching 解决方案。仅允许基于访客所在国家/地区访问 Rails 应用程序。

我已经实现了以下代码:

allowed_countries:  ['US', 'FR']

和:

def check_country

  country         = GeoIP::Country.new(APP_CONFIG['geocountry'])
  country_result  = country.look_up(request.remote_ip) if Rails.env.production?
  country_result  = country.look_up("your_hardcoded_ip_here") if Rails.env.development?
  @country_code = country_result[:country_code]

  if APP_CONFIG["allowed_countries"].include?(@country_code)
    raise("accepted country")
  else
    raise("failed country")
  end

end

完美运行(您需要付费搜索 maxmind geoip 的 geoip 数据库)

我在之前的过滤器中有这个,需要一个好的缓存解决方案,这样它就不会在每次请求时被调用

有什么想法吗?

4

0 回答 0