provision

0.0.2 • Public • Published

node-provision

Description

node-provision is a node middleware that analyze http request.

it can detect followings:

  • language
  • country
  • geo location
  • browser type (mobile, tablet, desktop)

Dependencies

Installation

see geoip.

  1. Install libGeoIP shared libraries.
  2. Download GeoLiteCity.dat and place it in /usr/local/share/GeoIP (see note below on file placement).

next,

  npm install provision

Usage

  var provision = require('provision');
  
  ...
  app.use(provision.middleware());

you can configure options and functions.

  provision.options = {
    monomi: true,
    useragent: true,
    geoip: true,
    language: true
  };
  
  provision
  .canProvisioning(function(req, options) {
    // if no need to provision request, return false.
    if (req.session && req.session.provision)
      return false;
    // do provisioning
    return true;
  })
  .afterProvisioning(function(req, res, next, data) {
    var prov = {};
    prov.locale = data.language;
    prov.country = data.country;
    prov.family = data.family;
    prov.os = data.os;
    prov.osVersion = data.osVersion;
    prov.browserType = data.browserType;
 
    if (data.location) {
      prov.location = {};
      prov.location.latitude = data.location.latitude;
      prov.location.longitude = data.location.longitude;
    }
 
    // save provision data.
    req.session.provision = prov;
    next();
  });

provision data below:

{ location: 
   { country_code: 'US',
     country_code3: 'USA',
     country_name: 'United States',
     region: 'CA',
     city: 'Mountain View',
     postal_code: '94043',
     latitude: 37.4192008972168,
     longitude: -122.05740356445312,
     metro_code: 807,
     dma_code: 807,
     area_code: 650,
     continent_code: 'NA' },
  country: 'us',
  language: 'ko',
  browserType: 'desktop',
  family: 'Chrome',
  os: 'Mac OS X',
  osVersion: '15' }

Run the tests

  npm test

Author: [Simyung Kim(http://simyungk.blogspot.com)

Readme

Keywords

none

Package Sidebar

Install

npm i provision

Weekly Downloads

0

Version

0.0.2

License

none

Last publish

Collaborators

  • simyungk