Last active
August 7, 2024 06:11
-
-
Save kyrylo/563a8cb6f44532b58ccb48bf0d30651f to your computer and use it in GitHub Desktop.
Revisions
-
kyrylo revised this gist
Aug 5, 2024 . No changes.There are no files selected for viewing
-
kyrylo created this gist
Aug 5, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ # frozen_string_literal: true class ApplicationService def self.call(...) new(...).call end def initialize(...) end end class CurrentIpService < ApplicationService def initialize(request) super @request = request end def call ip_headers = [ @request.env["HTTP_CF_CONNECTING_IP"], @request.env["HTTP_CLIENT_IP"], @request.env["HTTP_X_FORWARDED_FOR"], @request.env["HTTP_X_FORWARDED"], @request.env["HTTP_FORWARDED_FOR"], @request.env["HTTP_FORWARDED"], @request.env["REMOTE_ADDR"] ] (ip_headers.find(&:present?) || "127.0.0.1").split(",").first end end CurrentIpService.call(request)