connect-condition
v0.1.0
Published
middleware to conditionally select middlewares
Downloads
3
Maintainers
Readme
connect-condition
middleware to conditionally select middlewares
Table of Contents
Description
Use conditional middlewares within connect or express.
If condition
returns true, then middleware_true
is processed. Otherwise it's middleware_false
.
Returns: function - function (req, res, next)
| Param | Type | Description |
| --- | --- | --- |
| condition | function | function (req, res)
|
| middleware_true | function | function (req, res, next)
middleware executed if condition
returns true |
| [middleware_false] | function | function (req, res, next)
middleware executed if condition
returns false |
Example
require('http').createServer(
condition(
function (req, res) { // condition
if (~req.url.indexOf('json')) {
return true
}
},
function (req, res, next) { // middleware which is choosen on condition == true
res.setHeader('Content', 'application/json')
res.end('{ "text": "as json" }\n')
},
function (req, res, next) { // middleware which is choosen on condition == false
res.end('just text\n')
}
)
).listen(3000)
Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work or correctly attributed with the source of its origin and licence.
License
Copyright (c) 2015 commenthol (MIT License)
See LICENSE for more info.