Socket
Socket
Sign inDemoInstall

@emartech/cls-adapter

Package Overview
Dependencies
7
Maintainers
62
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @emartech/cls-adapter

Wrapper around cls-hooked for easier access


Version published
Weekly downloads
440
decreased by-18.97%
Maintainers
62
Install size
296 kB
Created
Weekly downloads
 

Readme

Source

cls-adapter

Wrapper around cls-hooked for easier access.

The aim is to store the unique request identifier from the header (X-Request-Id) and make it available on any function call that is after the middleware during a request lifecycle. This way at any point of the application we can retrieve the request identifier from the storage without having to pass it down to every function call. We can even add more information to the storage besides the request identifier and access it in consecutive function calls.

Basic usage

// Add middleware to Koa app
const Koa = require('koa');
const clsAdapter = require('@emartech/cls-adapter');
const port = 3000;

const app = new Koa();

app.use(clsAdapter.getKoaMiddleware());

app.use(async (ctx) => {
  clsAdapter.setOnContext('customer_id', Math.round(Math.random() * 1000));

  // will return an object with request_id and customer_id property set
  console.log(clsAdapter.getContextStorage());

  ctx.body = 'It works';
});

app.listen(port);
console.log('listening on port: ' + port);

FAQs

Last updated on 08 Feb 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc