Exclude /metrics and /status routes from session initialization
This commit adds a `useUnless` helper method which can be used as a middleware for express. It receives an express-middleware and an array of paths. When a request matches one of the given paths, this middleware does nothing. Otherwise the given middleware is called. For the express-session middleware this helper middleware is used to avoid session creation on purely status routes. See #1446 Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
@@ -25,3 +25,12 @@ exports.getImageMimeType = function getImageMimeType (imagePath) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
exports.useUnless = function excludeRoute (paths, middleware) {
|
||||
return function (req, res, next) {
|
||||
if (paths.includes(req.path)) {
|
||||
return next()
|
||||
}
|
||||
return middleware(req, res, next)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user