1.0.26 • Published 2 years ago

@layeredapps/maxmind-geoip v1.0.26

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Documentation for Maxmind GeoIP module

Shortcuts

Index

Introduction

Dashboard bundles everything a web app needs, all the "boilerplate" like signing in and changing passwords, into a parallel server so you can write a much smaller web app.

MaxMind provide a database that converts IP addresses to countries and this module adds API routes for identifying the country by IP and a server handler that will automatically attach a Country object to each HttpRequest using their database. There is much more data in the MaxMind database than is exposed via the API, pull requests are welcome to add more routes to access it.

Import this module

Install the module with NPM:

$ npm install @layeredapps/maxmind-geoip

Edit your package.json to activate the module:

"dashboard": {
  "modules": [
    "@layeredapps/maxmind-geoip"
  ]
}

Provided server, content and proxy handlers

This module comes with some convenience scripts you can add to your package.json:

TypeScript pathDescription
proxy@layeredapps/maxmind-geoip/src/proxy/x-country.jsInclude the Maxmind Country object in x-country header
server@layeredapps/maxmind-geoip/src/server/bind-country.jsThe MaxMind Country object will be bound to req.country

Access the API

Dashboard and official modules are completely API-driven and you can access the same APIs on behalf of the user making requests. You perform GET, POST, PATCH, and DELETE HTTP requests against the API endpoints to fetch or modify data. This example fetches the user's country information using NodeJS, you can do this with any language:

const country = await proxy(`/api/user/geoip/country?ip=1.2.3.4`, accountid, sessionid)

const proxy = util.promisify((path, accountid, sessionid, callback) => {
    const requestOptions = {
        host: 'dashboard.example.com',
        path: path,
        port: '443',
        method: 'GET',
        headers: {
            'x-application-server': 'application.example.com',
            'x-application-server-token': process.env.APPLICATION_SERVER_TOKEN
        }
    }
    if (accountid) {
        requestOptions.headers['x-accountid'] = accountid
        requestOptions.headers['x-sessionid'] = sessionid
    }
    const proxyRequest = require('https').request(requestOptions, (proxyResponse) => {
        let body = ''
        proxyResponse.on('data', (chunk) => {
            body += chunk
        })
        return proxyResponse.on('end', () => {
            return callback(null, JSON.parse(body))
        })
    })
    proxyRequest.on('error', (error) => {
        return callback(error)
    })
    return proxyRequest.end()
  })
}
1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago