mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
929f824a3a
* fix: refactor conditional middleware * fix: update tests * test: update snapshot to hide things behing flag from openapi Co-authored-by: kwasniew <kwasniewski.mateusz@gmail.com>
19 lines
387 B
TypeScript
19 lines
387 B
TypeScript
import { RequestHandler, Router } from 'express';
|
|
|
|
export const conditionalMiddleware = (
|
|
condition: () => boolean,
|
|
middleware: RequestHandler,
|
|
): RequestHandler => {
|
|
const router = Router();
|
|
|
|
router.use((req, res, next) => {
|
|
if (condition()) {
|
|
middleware(req, res, next);
|
|
} else {
|
|
next();
|
|
}
|
|
});
|
|
|
|
return router;
|
|
};
|