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
Fredrik Strand Oseberg 85b45b9965
Feat/unleash flags embedded proxy (#1974)
* 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>
2022-08-26 15:16:29 +02:00

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