1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/src/lib/middleware/conditional-middleware.ts

19 lines
387 B
TypeScript
Raw Normal View History

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;
};