Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including edgescape-parser with all npm packages installed. Try it out:

var edgescapeParser = require("edgescape-parser")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

edgescape-parser v1.0.0

Middleware for parsing the Akamai EdgeScape header

edgescape-parser

Middleware for parsing the Akamai EdgeScape header

Install

$ npm install --save edgescape-parser

Usage

var express = require('express');
var edgescapeParser = require('edgescape-parser');

var app = express();

app.use(edgescapeParser());

app.get('/:country_code?', function(req, res) {

  // redirect homepage to country code
  if(_.isUndefined(req.params.country_code)) {
    var country_code = req.akamai.edgescape.country_code.toLowerCase() || 'us';
    res.redirect(302, '/' country_code);
  } else {
    // Render country specific page
  }

});

API

edgescapeParser([options])

options

header

Type: string
Default: x-akamai-edgescape

Parses the header into a JSON object containing all of the EdgeScape variables.

Attribute NameAvailabilityValue TypeDescription
country_codeglobalstringTwo-letter ISO-3166-1 country code
region_codeglobalstring/integerProvince, region or state code. Not available in all countries.
cityglobalstring
dmaUnited StatesintegerDesignated Marketing Area - the same as the Nielson definition.
pmsaUnited StatesintegerPrimary Metropolitan Statistical Area, a measure by the US government. There is no direct correlation for these measures outside the US.
msaUnited StatesintegerA number representing the Metropolitan Statistical Area.
area codeUnited Statesinteger-array‘+’ delimited array of phone area codes associated with the client IP address.
countyUnitedStates string
fipsUnited StatesintegerNumerical value for the county
latglobalfloatGlobal latitude position
longglobalfloatGlobal longitude position
timezoneglobalstring GMT + offset
zipUnited States + Canadazipcode-range-array‘+’ delimited array of zipcode ranges. ‘-’ indicates the range. Note that this field is based on the ‘city’ field, so that is the current granularity level.
continentglobalstring
throughputglobalstringSee the “Actual Connection Speed (throughput)” file under Support > User and Developer Guides > Content Targeting > Data Codes.
bwglobalintegerProvides additional granularity to the ‘throughput’ field.
asnumglobalinteger-array‘+’ delimited array of Autonomous System (AS) numbers.
networkglobal, select networksstringThe name of the network/ISP that owns the IP address, including wireless carriers. Select networks only.
network_typeglobalstringThe connection type seen in the end user’s request (e.g., dialup, cable, dsl)
proxyglobalstringThis value is set if the IP is a proxy.

License

MIT © MadGlory

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free