0

国ベースの小切手のためのチャッシング ソリューションが必要です。訪問者の国に基づいて 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

完璧に動作します (有料検索である geoip データベースが必要です maxmind geoip )

しかし

これは私が前のフィルターに持っているもので、リクエストごとに呼び出されないように適切なキャッシュソリューションが必要です

何かご意見は?

4

0 に答える 0