Invokes connect-like middleware if / unless routing criteria match.
Inspired by the express-unless module. But a lot faster ;)
- Advanced routes matching capabilities. Uses find-my-way or any compatible router to match the routes.
iff: execute middleware only if routing criteria is a match. Ideal use case: API gateways (see: fast-gateway)unless: execute middleware unless routing criteria is a match.- Arbitraty chaining of
iff -> unlessof vice-versa. - Low overhead, blazing fast implementation.
Install
npm i middleware-if-unlessExtending middleware
constiu=require('middleware-if-unless')()constmiddleware=function(req,res,next){res.body='hit'returnnext()}// extend middleware with iff/unless capabilitiesiu(middleware)Execute middleware unless routing criteria is a match:
constapp=require('express')()app.use(middleware.unless(['/not/allowed/to/hit']))...In this example, all requests except [GET] /not/allowed/to/hit will cause the middleware to be executed.
Execute middleware only if routing criteria is a match:
constapp=require('express')()app.use(middleware.iff([{methods: ['POST','DELETE','PUT','PATCH'],url: '/tasks/:id'}]))...In this example, only a [POST|DELETE|PUT|PATCH] /tasks/:id request will cause the middleware to be executed.
- Website and documentation: https://iff-unless.21no.de