function createFlagGuard
Since 0.1.0
createFlagGuard(
flag: string,
): MiddlewareFunction

Creates a middleware function that guards a route based on a feature flag.

Resolves IFeatureFlags from the service registry per request, evaluates the flag, and either calls next() (flag on) or short-circuits to a redirect / 404 (flag off).

When the CAPABILITIES.FEATURE_FLAGS capability is unregistered, the registry's error propagates — the guard does not fail silently.

Examples

Example 1

app.get('/dashboard', [
  createFlagGuard('new-dashboard', { fallback: '/old' }),
  () => c.text('New dashboard'),
]);

Parameters

flag: string

Flag name to evaluate.

optional
options: FlagGuardOptions

Guard options (fallback URL, status code, context override).

Return Type

MiddlewareFunction

A middleware function.

Throws

Error

If CAPABILITIES.FEATURE_FLAGS is not registered.

Usage

import { createFlagGuard } from "feature-flags-plugin/src/index.ts";