Skip middleware when a path matches
This package works with Express v5. For Express v4 support, use express-except@1
.
npm install express-except
require('express-except')
app.useExcept('/skip', (req, res) => res.send('stopped'))
app.use((req, res) => res.send('skipped'))
// GET /skip => skipped
// GET /other => stopped
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.
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
yarn
yarn build
yarn test
MIT