mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
85b45b9965
* feat: use unleash flags for embedded proxy * feat: add a separate flag for the proxy frontend * fix: setup unleash in dev * fix: check flagResolver on each request * fix: remove unleash client setup * refactor: update frontend routes snapshot * refactor: make batchMetrics flag dynamic * fix: always check dynamic CORS origins config * fix: make conditionalMiddleware work with the OpenAPI schema generation Co-authored-by: olav <mail@olav.io>
20 lines
435 B
TypeScript
20 lines
435 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()) {
|
|
next();
|
|
} else {
|
|
res.status(404).send({ message: 'Not found' });
|
|
}
|
|
});
|
|
|
|
router.use(middleware);
|
|
return router;
|
|
};
|