express-except
v2.0.0
Published
Skip middleware when a path matches
Downloads
27
Readme
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 => stopped
Explanation
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.useExcept
app.allExcept
app.getExcept
,app.postExcept
, etc.router.useExcept
router.allExcept
router.getExcept
,router.postExcept
, etc.
path
- An Express path that should be skipped over. If the path of the request matches, the passedmiddleware
will 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 test
License
MIT