Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

maybe-middleware

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

maybe-middleware

Wrapper for enable or disable express or connect middleware based on condition.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

maybe-middleware

Wrapper for enable or disable express or connect middleware based on condition.

This wrapper allow you to enable or disable an express or connect middleware. In some circumstances you would use a middleware only if some conditions are met.

Installation

If you want use maybe-middleware you have to install it. There are two methods for that: In your package.json add the following item:

"maybe-middleware": "version"

then digit

npm install

Example:

"maybe-middleware": "*" for the latest version
"maybe-middleware": "1.0.0" for the version 1.0.0

OR

launch this command:

npm install maybe-middleware --save
Use
var maybeMiddleware = require('maybe-middleware');

// Import some other required modules
var express = require('express');
var app = express();
var responsePoweredBy = require('response-powered-by');
var POWERED_BY = "@NIckNaso";
// Some other configuration for the express app and session

// predicate as boolean
app.use(maybeMiddleware(responsePoweredBy(POWERED_BY), true));
//  OR
// predicate as function
app.use(maybeMiddleware(
  responsePoweredBy(POWERED_BY),
  function () {
    // some other instructions ...
    return true;
  }
));

The first parameter for maybe-middleware is an express middleware, while the second is a boolean value or a function that return a boolean value. If the parameter's type do not match with those required an error will be dispatched to the express error middleware. In pariticular the error will be an instance of MaybeMiddlewareError.

Keywords

FAQs

Package last updated on 21 Jan 2017

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