2.0.0 • Published 1 year ago
express-except v2.0.0
express-except
Skip middleware when a path matches
This package works with Express v5. For Express v4 support, use express-except@1.
Install
npm install express-except
Usage
require('express-except')
app.useExcept('/skip', (req, res) => res.send('stopped'))
app.use((req, res) => res.send('skipped'))
// GET /skip => skipped
// GET /other => stoppedExplanation
When you require this package, the following Express middleware mounting
methods are added:
app.useExcept(opposite ofapp.use)app.allExcept(opposite ofapp.all)app[METHOD + 'Except'](opposite ofapp[METHOD])router.useExcept(opposite ofrouter.use)router.allExcept(opposite ofrouter.all)router[METHOD + 'Except'](opposite ofrouter[METHOD])
You can then use one of those methods to mount middleware that WILL NOT run if the path matches. Each new method has the same signature as its corresponding Express method. This library uses only built-in Express functionality and does not attempt to match routes manually.
Documentation
fn(path, ...middleware):
fn- One of:app.useExceptapp.allExceptapp.getExcept,app.postExcept, etc.router.useExceptrouter.allExceptrouter.getExcept,router.postExcept, etc.
path- An Express path that should be skipped over. If the path of the request matches, the passedmiddlewarewill be skipped. Supports any of Express Path Examples.middleware- An Express callback or router, an array of callbacks and/or routers, or a mix of these
Development
yarn
yarn build
yarn testLicense
MIT