mm

maybe-middleware

Wrapper for dinamically enable or disable express middleware

Showing:

Popularity

Downloads/wk

5

GitHub Stars

1

Maintenance

Last Commit

5yrs ago

Contributors

0

Package

Dependencies

0

License

Apache-2.0

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial