inbound-middleware

Express middleware for parsing inbound user information


Keywords
express, request, referrer
Install
npm install inbound-middleware@0.1.1

Documentation

inbound-middleware

An Express middleware for parsing inbound user information. The following data are parsed from the request object:

  • Referer information using database from referer-parser
  • UTM tags
  • IP address and its geoip info

Installation

npm:

npm install inbound-middleware

yarn:

yarn add inbound-middleware

Usage

Add inbound-middleware to your middleware stack:

import inbound from 'inbound-middleware';

// ...
server.use(inbound());

All parsed information is stored at req.inbound.

server.use((req: Request, res: Response, next: NextFunction) => {
  if (req.inbound !== null) {
    console.log(req.inbound.referrer);
  }
 });

You can also specify options while initializing the middleware.

const options = {
   // Domains of the site (default: [])
  internalDomains: ['foo.com'],
  // When set to true, req IP will not be parsed and req.inbound.ip will be null. (default: false)
  skipIP: false,
  // When set to true, the referrer database will be fetched from the web. (default: true)
  // Otherwise, local database stored in data/referers.json will be used.
  webReferralDB: true,
  // Cron schedule string for updating the referrer database.
  // This is only effective when webReferralDB is true. (default: '0 0 0 * * * *')
  updateSchedule: '0 0 0 * * * *'
};
server.use(inbound(options));

See the node-cron docs for the cron schedule syntax.

Lincense

MIT