conditional-middleware
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "conditional-middleware", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Conditional, composable middleware for connect, express, and other soon-to-be available server modules.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -124,3 +124,3 @@ # conditional-middleware | ||
## But what if the condtion returns false | ||
## But what if the condtion returns false? | ||
@@ -149,2 +149,30 @@ Other modules like [express-conditional-middleware](https://www.npmjs.com/package/express-conditional-middleware) accept a "failure" function for when the condition fails. However, this is not necessary becuase the very next middleware will always run when the condition fails. Continuing with the basic example above, here is how you might handle a simple failure scenario: | ||
}); | ||
``` | ||
## What about nesting? | ||
Yup, that works too! | ||
```js | ||
const express = require('express'); | ||
const conditional = require('conditional-middleware'); | ||
const app = express(); | ||
app.use(conditional(() => true, [ | ||
(req, res, next) => { | ||
req.foo = true; | ||
next(); | ||
}, | ||
conditional(() => true, [ | ||
(req, res, next) => { | ||
req.bar = true; | ||
next(); | ||
} | ||
]), | ||
(req, res, next) => { | ||
assert.ok(req.foo, 'foo is set'); | ||
assert.ok(req.bar, 'bar is set'); | ||
next() | ||
} | ||
])); | ||
``` |
@@ -184,2 +184,25 @@ const assert = require('chai').assert; | ||
}); | ||
describe('nesting conditionals', () => { | ||
it('works', done => { | ||
const middleware = conditional(() => true, [ | ||
(req, res, next) => { | ||
req.foo = true; | ||
next(); | ||
}, | ||
conditional(() => true, [ | ||
(req, res, next) => { | ||
req.bar = true; | ||
next(); | ||
} | ||
]), | ||
(req, res, next) => { | ||
assert.ok(req.foo, 'foo is set'); | ||
assert.ok(req.bar, 'bar is set'); | ||
next(); | ||
} | ||
]); | ||
middleware({}, {}, done); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49146
241
176