Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GeoIpLocator

Geo IP locator which retrieves location of the IP address.
Locator has a set of repositories from where locations are fetched. Repositories are load balanced via weighted round robin algorithm, and tried in order until some of them retrieves location.

Hierarchy

  • GeoIpLocator

Constructors

Methods

Constructors

constructor

  • new GeoIpLocator(repositories: readonly IpLocationsRepository[]): GeoIpLocator
  • Parameters

    • repositories: readonly IpLocationsRepository[]

      Repositories from where locations can be fetched.

    Returns GeoIpLocator

Methods

locate

  • locate(ip: string, repo?: string): Promise<null | IpLocation>
  • Retrieves location associated with an IP.

    Notice that location might differ when invoking this function with the same ip multiple times.
    This is caused by the way repositories are selected by load balancer in order to retrieve location for that ip.
    If you need same location object at each invocation, you can explicitly define repo from where to fetch location. Notice that location has IpLocation.REPOSITORY_ID property which indicates from which repository it was retrieved.

    Parameters

    • ip: string

      Ip address.

    • Optional repo: string

      Id of the repository from where to fetch location.

    Returns Promise<null | IpLocation>

    Ip location.