{"id":20426537,"url":"https://github.com/futurestudio/hapi-geo-locate","last_synced_at":"2025-04-09T09:08:23.710Z","repository":{"id":34178272,"uuid":"76848591","full_name":"futurestudio/hapi-geo-locate","owner":"futurestudio","description":"A hapi plugin to geo locate requests","archived":false,"fork":false,"pushed_at":"2025-03-25T08:37:23.000Z","size":528,"stargazers_count":36,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T02:36:24.494Z","etag":null,"topics":["client-location","future-studio-university","geo","geolocation","hapi","hapi-plugin","hapijs","ipinfo","proxies"],"latest_commit_sha":null,"homepage":"https://futurestud.io/tutorials/hapi-geo-locate-hapi-plugin-for-client-geo-location-by-future-studio","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/futurestudio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-19T09:38:42.000Z","updated_at":"2025-03-25T08:37:20.000Z","dependencies_parsed_at":"2023-02-17T03:20:16.609Z","dependency_job_id":"30f5dcbe-6f11-46d9-96e0-da9b84e7231e","html_url":"https://github.com/futurestudio/hapi-geo-locate","commit_stats":{"total_commits":349,"total_committers":8,"mean_commits":43.625,"dds":0.5100286532951289,"last_synced_commit":"52ad17639c1e61ab7e695f20e3306e3e8b200e45"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-geo-locate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-geo-locate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-geo-locate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-geo-locate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/futurestudio","download_url":"https://codeload.github.com/futurestudio/hapi-geo-locate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008630,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client-location","future-studio-university","geo","geolocation","hapi","hapi-plugin","hapijs","ipinfo","proxies"],"created_at":"2024-11-15T07:16:50.693Z","updated_at":"2025-04-09T09:08:23.694Z","avatar_url":"https://github.com/futurestudio.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"471\" style=\"max-width:100%;\" src=\"https://github.com/futurestudio/hapi-geo-locate/blob/master/media/hapi-geo-locate.png?raw=true\" alt=\"hapi-geo-locate logo\"\u003e\n\n  \u003cbr/\u003e\n  \u003cbr/\u003e\n\n  \u003cp\u003e\n    A hapi plugin to geo-locate requests\n  \u003c/p\u003e\n  \u003cbr/\u003e\n  \u003cp\u003e\n    \u003ca href=\"#installation\"\u003e\u003cstrong\u003eInstallation\u003c/strong\u003e\u003c/a\u003e ·\n    \u003ca href=\"#usage\"\u003e\u003cstrong\u003eUsage\u003c/strong\u003e\u003c/a\u003e ·\n    \u003ca href=\"#plugin-registration-options\"\u003e\u003cstrong\u003ePlugin Options\u003c/strong\u003e\u003c/a\u003e ·\n    \u003ca href=\"#supported-proxies-and-proxy-headers\"\u003e\u003cstrong\u003eProxies and Headers\u003c/strong\u003e\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cbr/\u003e\n  \u003cbr/\u003e\n  \u003cp\u003e\n    \u003ca href=\"https://travis-ci.org/futurestudio/hapi-geo-locate\"\u003e\u003cimg src=\"https://travis-ci.org/futurestudio/hapi-geo-locate.svg?branch=master\" alt=\"Build Status\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://snyk.io/test/github/futurestudio/hapi-geo-locate\"\u003e\u003cimg src=\"https://snyk.io/test/github/futurestudio/hapi-geo-locate/badge.svg\" alt=\"Known Vulnerabilities\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/hapi-geo-locate\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/hapi-geo-locate.svg\" alt=\"Latest Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/hapi-geo-locate\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/hapi-geo-locate.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    \u003cem\u003eFollow \u003ca href=\"http://twitter.com/marcuspoehls\"\u003e@marcuspoehls\u003c/a\u003e for updates!\u003c/em\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\u003csup\u003eDevelopment of this hapi plugin is supported by \u003ca href=\"https://futurestud.io\"\u003eFuture Studio University 🚀\u003c/a\u003e\u003c/sup\u003e\n\u003cbr\u003e\u003cb\u003e\nJoin the \u003ca href=\"https://futurestud.io/university\"\u003eFuture Studio University and Skyrocket in Node.js\u003c/a\u003e\u003c/b\u003e\n\u003c/p\u003e\n\n---\n\n## Introduction\nA hapi plugin to geo locate requests by IP and provide `request.location` in your route handlers. The plugin uses [ipinfo.io](http://ipinfo.io/) for the IP geo location.\n\n\n## Requirements\n\u003e **hapi v19 (or later)** and **Node.js v12 (or newer)**\n\nThis plugin requires **hapi v19** (or later) and **Node.js v12 or newer**.\n\n\n### Compatibility\n| Major Release | [hapi.js](https://github.com/hapijs/hapi) version | Node.js version |\n| --- | --- | --- |\n| `v4` | `\u003e=17 hapi` | `\u003e=12` |\n| `v3` | `\u003e=17 hapi` | `\u003e=8` |\n| `v2` | `\u003c=16 hapi` | `\u003e=8` |\n\n\n## Installation\nAdd `hapi-geo-locate` as a dependency to your project:\n\n```bash\nnpm i hapi-geo-locate\n```\n\n\n### Using hapi v17 or v18?\nUse the `3.x` release line:\n\n```bash\nnpm i hapi-geo-locate@3\n```\n\n\n### Do you use hapi v16 (or lower)?\nUse the `2.x` release of `hapi-geo-locate` with hapi v16 support. Later versions are only compatible with hapi v17 and v18.\n\n```bash\nnpm i hapi-geo-locate@2\n```\n\n\n## Usage\nThe most straight forward way to register the `hapi-geo-locate` plugin:\n\n```js\nawait server.register({\n    plugin: require('hapi-geo-locate')\n})\n\n// went smooth like dark chocolate :)\n\n// Within your route handler functions, you can access the location like this\nserver.route({\n    method: 'GET',\n    path: '/',\n    handler: (request, h) =\u003e {\n        const location = request.location\n\n        // use client location\n\n        return location\n    }\n})\n```\n\n\n## Plugin Registration Options\nThe following plugin options allow you to customize the default behavior of `hapi-geo-locate`:\n\n- **enabledByDefault**: `(boolean)`, default: `true` — by default, the plugin geo locates the request by IP on every request\n- **authToken**: `(string)`, no default — the API token to authenticate requests against the IPinfo API\n\n```js\nawait server.register({\n  plugin: require('hapi-geo-locate'),\n  options: {\n    enabledByDefault: false\n    authToken: 'your-ipinfo-api-token'\n  }\n})\n\n// Within your route handler functions, you can access the location like this\nserver.route({\n  method: 'GET',\n  path: '/',\n  handler: (request, h) =\u003e {\n    const location = request.location // will be undefined\n\n    return h.response(location)\n  }\n})\n```\n\n\n## Route Handler Options\nThe following plugin options on individual route handlers allow you to customize the behavior of `hapi-geo-locate`:\n\n- **enabled**: `(boolean)` — tells the plugin to enable (`true`) or disable (`false`) geo location for the request by IP\n- **fakeIP**: `(string)` — tells the plugin to use the defined IP address to geo locate the request (by this IP)\n\nThe plugin configuration can be customized for single routes using the `hapi-geo-locate` key:\n\n```js\nserver.register({\n  plugin: require('hapi-geo-locate') // enabled by default\n})\n\n// Within your route handler functions, you can access the location like this\nserver.route({\n  method: 'GET',\n  path: '/',\n  handler: (request, h) =\u003e {\n    const location = request.location\n    // use the location\n\n    return location\n  },\n  config: {\n    plugins: {\n      'hapi-geo-locate': {\n        enabled: true,\n        fakeIP: '8.8.8.8'\n      }\n    }\n  }\n})\n```\n\n\n## Supported Proxies and Proxy Headers\n`hapi-geo-locate` supports all proxies that [request-ip](https://github.com/pbojinov/request-ip) does:\n\n- `X-Client-IP`\n- `X-Forwarded-For`, picking the first, client IP if the request went through multiple proxies.\n- `X-Forwarded`, `Forwarded-For` and `Forwarded` as variations of `X-Forwarded-For`\n- `CF-Connecting-IP`\n- `True-Client-Ip`\n- `X-Real-IP`\n- `X-Cluster-Client-IP`\n- and all the `request.[connection|socket|info].remoteAddress` variations.\n\nIf the IP address cannot be found, `null` is returned.\n\nRunning your application behind a (reverse) proxy like nginx, the client’s IP address gets reset to localhost.\nYou can grab the actual request IP to your app using an HTTP header.\n\n`hapi-geo-locate` uses the [request-ip](https://github.com/pbojinov/request-ip) package to determine the external IP address. This package supports\nall common HTTP headers and ways to get the request’s IP. Awesome!\n\nYou should be safe in any way :)\n\n\n## Feature Requests\nDo you miss a feature? Please don’t hesitate to\n[create an issue](https://github.com/futurestudio/hapi-geo-locate/issues) with a short description of your\ndesired addition to this plugin.\n\n\n## Links \u0026 Resources\n- [hapi tutorial series (100+ tutorials)](https://futurestud.io/tutorials/hapi-get-your-server-up-and-running)\n- [node-ipinfo](https://github.com/IonicaBizau/node-ipinfo): Node.js wrapper for the [ipinfo.io](http://ipinfo.io) API\n- [request-ip](https://github.com/pbojinov/request-ip): Node.js module for retrieving a request’s IP address\n\n\n## Contributing\n1. Create a fork\n2. Create your feature branch: `git checkout -b my-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 🚀\n\n\n## License\nMIT © [Future Studio](https://futurestud.io)\n\n---\n\n\u003e [futurestud.io](https://futurestud.io) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e GitHub [@futurestudio](https://github.com/futurestudio/) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e Twitter [@futurestud_io](https://twitter.com/futurestud_io)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturestudio%2Fhapi-geo-locate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuturestudio%2Fhapi-geo-locate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturestudio%2Fhapi-geo-locate/lists"}