Socket
Socket
Sign inDemoInstall

request-received

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-received

Route middleware for Koa and Express that adds a request received high-resolution timer and Date to the request object using easily accessible Symbols to prevent request object pollution. Made for Cabin.


Version published
Weekly downloads
759
decreased by-27.09%
Maintainers
1
Weekly downloads
 
Created
Source

request-received

build status code coverage code style styled with prettier made with lass license npm downloads

Route middleware for Koa and Express that adds a request received high-resolution timer and Date to the request object using easily accessible Symbols to prevent request object pollution. Made for Cabin.

Table of Contents

Install

npm:

npm install request-received

yarn:

yarn add request-received

Usage

Express

Symbols are automatically added to req object in route middleware:

const express = require('express');
const Cabin = require('cabin');
const requestReceived = require('request-received');
const responseTime = require('response-time');
const requestId = require('express-request-id');

const startAt = Symbol.for('request-received.startAt');
const startTime = Symbol.for('request-received.startTime');

const app = express();
const Cabin = new Cabin();

app.use(requestReceived);

app.use((req, res, next) => {
  console.log('startAt', req[startAt]); // `process.hrtime()`
  // [ 472542, 431456521 ]
  console.log('startTime', req[startTime]); // new Date()
  // 2000-01-01T06:00:00.000Z
  next();
});

app.use(responseTime());
app.use(requestId());
app.use(cabin.middleware);

app.listen();

Koa

Symbols are automatically added to ctx, ctx.req, and ctx.request objects in route middleware:

const Koa = require('koa');
const koaConnect = require('koa-connect');
const responseReceived = require('response-received');
const responseTime = require('response-time');
const requestId = require('express-request-id');

const startAt = Symbol.for('request-received.startAt');
const startTime = Symbol.for('request-received.startTime');

const app = new Koa();
const Cabin = new Cabin();

app.use(requestReceived);

app.use((ctx, next) => {
  console.log('startAt', ctx[startAt]); // `process.hrtime()`
  // [ 472542, 431456521 ]
  console.log('startTime', ctx[startTime]); // new Date()
  // 2000-01-01T06:00:00.000Z

  // note that the symbols are also accessible via:
  // ctx.req[startAt]
  // ctx.request[startAt]
  // ctx.req[startTime]
  // ctx.request[startTime]

  return next();
});

app.use(koaConnect(responseTime));
app.use(requestId());
app.use(cabin.middleware);

app.listen();

Contributors

NameWebsite
Nick Baughhttp://niftylettuce.com/

License

MIT © Nick Baugh

Keywords

FAQs

Package last updated on 13 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc