Skip to content

lrdiv/koa-geoip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-geoip

IP-based geolocation middleware for Koa

Installation (via npm)

$ npm install koa-geoip

Usage

var koa = require('koa');
var route = require('koa-route');
var geolocate = require('koa-geoip');
var app = koa();

app.use(geolocate());

app.use(route.get('/', function() {
  if (this.request.geolocation) {
    this.body = {
      city: this.request.geolocation.city,
      state: this.request.geolocation.region,
      country: this.request.geolocation.country,
      latlng: this.request.geolocation.ll
    }
  } else {
    this.body = {error: "Could not geolocate."};
  }
}));

app.listen(3000);

Options

whitelist

If the whitelist option is not provided, koa-geoip will be used on all routes. The whitelist option allows you to specify which routes the middleware should be used on.

app.use(geolocate({
  whitelist: ['/foo', '/bar', '/baz']
}));

Dependencies

node-geoip

License

MIT License

About

IP based geolocation middleware for koajs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published