express-conditional-middleware

Allow express middlewares to be overridden based on a condition.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
express-conditional-middleware
2.1.16 years ago9 years agoMinified + gzip package size for express-conditional-middleware in KB

Readme

Express Conditional Middleware
Greenkeeper badge
travis build Coverage Status
This module provides a conditional middleware for express. Use as follows:
var conditional = require('express-conditional-middleware');

// Simple boolean method.
app.use(conditional(true, function (req, res, next) {
  // ...
});

// Function method.
app.use(conditional(
  function (req, res, next) {
    return req.get('accept') === 'application/json';
  },
  function (req, res, next) {
    // ...
  }
));

// Failure middleware.
app.use(conditional(
  function (req, res, next) {
    return req.get('accept') === 'application/json';
  },
  function (req, res, next) {
    // Executed if 'accept' === 'application/json'
  },
  function (req, res, next) {
    // Executed if 'accept' !== 'application/json'
  }
));