You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

express-http-context

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-http-context - npm Package Compare versions

Comparing version

to
0.3.2

.travis.yml

40

index.js

@@ -7,15 +7,35 @@ 'use strict';

module.exports = {
middleware: function (req, res, next) {
const ns = cls.getNamespace(nsid) || cls.createNamespace(nsid);
ns.run(() => next());
},
get: function (key) {
const ns = cls.getNamespace(nsid);
/** Express.js middleware that is responsible for initializing the context for each request. */
function middleware(req, res, next) {
const ns = cls.getNamespace(nsid) || cls.createNamespace(nsid);
ns.run(() => next());
}
/**
* Gets a value from the context by key. Will return undefined if the context has not yet been initialized for this request or if a value is not found for the specified key.
* @param {string} key
*/
function get(key) {
const ns = cls.getNamespace(nsid);
if (ns.active) {
return ns.get(key);
},
set: function (key, value) {
const ns = cls.getNamespace(nsid);
}
}
/**
* Adds a value to the context by key. If the key already exists, its value will be overwritten. No value will persist if the context has not yet been initialized.
* @param {string} key
* @param {*} value
*/
function set(key, value) {
const ns = cls.getNamespace(nsid);
if (ns.active) {
return ns.set(key, value);
}
}
module.exports = {
middleware,
get: get,
set: set
}
{
"name": "express-http-context",
"version": "0.3.1",
"version": "0.3.2",
"description": "Get and set request-scoped context anywhere",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"cover": "istanbul cover ./node_modules/mocha/bin/_mocha index.js -R ./tests --coverage && istanbul check-coverage --statement 100 --branch 100 --function 100 --line 100",
"test": "mocha ./tests"
},

@@ -27,3 +28,10 @@ "repository": {

"continuation-local-storage": "^3.2.0"
},
"devDependencies": {
"chai": "^3.5.0",
"express": "^4.15.2",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"supertest": "^3.0.0"
}
}

@@ -0,1 +1,5 @@

[![travis](https://img.shields.io/travis/skonves/express-http-context.svg)](https://travis-ci.org/skonves/express-http-context)
[![npm](https://img.shields.io/npm/v/express-http-context.svg)](https://www.npmjs.com/package/express-http-context)
[![npm](https://img.shields.io/npm/dm/express-http-context.svg)](https://www.npmjs.com/package/express-http-context)
# Express HTTP Context

@@ -2,0 +6,0 @@ Get and set request-scoped context anywhere. This is just an unopinionated, idiomatic ExpressJS implementation of [continuation-local-storage](https://www.npmjs.com/package/continuation-local-storage). It's a great place to store user state, claims from a JWT, request/correlation IDs, and any other request-scoped data.