0.1.1 • Published 7 years ago

mali-iff v0.1.1

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
7 years ago

mali-iff

Conditionally add Mali middleware.

Opposite of mali-unless.

npm version build status

Installation

npm install mali-iff

API

mali-iff ⇒ function

Mali if middleware. Attach to any middleware and configure it to permit/pervent the middleware in question to be executed.

Returns: function - middleware

ParamTypeDescription
optionsObject | String | RegExp | function- If string and one of Mali Call Types do middleware only if call the specified call type - If string and not a call type, assumed to be a call name; and middleware is executed only if the call name is the name specified. Call names checks are not case sensitive. - If function it's a test function that returns true / false. If the function returns true for the given call, the middleware will run. The function will be passed the call context. - If RegExp instance, if call name matches the regexp the middleware is run.
options.nameString | Regex | ArrayA string, a RegExp or an array of any of those. If the call name matches, the middleware will run. Call names checks are not case sensitive.
options.typeString | ArrayA string or an array of strings. If the call type matches, the middleware will run.
options.customfunctionA test function that returns true / false. If the function returns true for the given request, the middleware will run. The function will be passed the call context.

Example

const requestId = require('mali-requestid')
const iff = require('mali-iff')
const CallType = require('mali-call-types')
const toJSON = require('mali-tojson')()

const rid = requestId()
rid.iff = iff
app.use(rid.iff('SomeMethod'))

toJSON.iff = iff
app.use(toJSON.iff({ type: [ CallType.UNARY, CallType.REQUEST_STREAM ] }))

License

Apache-2.0