
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
middleware-if-unless
Advanced tools
Invokes connect-like middleware if / unless routing criteria matches. Inspired on express-unless module.
Invokes connect-like middleware if / unless routing criteria match.
Inspired by the express-unless module.
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.iff -> unless
of vice-versa.Install
npm i middleware-if-unless
Extending middleware
const iu = require('middleware-if-unless')()
const middleware = function (req, res, next) {
res.body = 'hit'
return next()
}
// extend middleware with iff/unless capabilities
iu(middleware)
Execute middleware unless routing criteria is a match:
const app = 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:
const app = 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.
FAQs
Invokes connect-like middleware if / unless routing criteria matches. Inspired on express-unless module.
The npm package middleware-if-unless receives a total of 945 weekly downloads. As such, middleware-if-unless popularity was classified as not popular.
We found that middleware-if-unless demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.