JSPM

provision

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q27281F

A request provisioning for node.js

Package Exports

  • provision

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (provision) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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)