@supabase/middleware - v0.2.0
    Preparing search index...

    Function pipeline

    • Compose a flat list of middleware entries around a handler (first = outermost, runs first on the request). Returns a FetchHandler ready for export default { fetch: … }.

      The handler's ctx is inferred as BaseContext plus every entry's contribution — no manual annotation. Ordering and collision errors surface on the handler argument so they don't break tuple inference on entries.

      Under the hood, pipeline folds the array into the same nested calls as hand-nesting — there is no new runtime behavior.

      Type Parameters

      • const Entries extends readonly AnyEntry[]

      Parameters

      • entries: Entries
      • handler: [Validate<Entries, object>] extends [true]
            ? (req: Request, ctx: Accumulate<Entries, object>) => Promise<Response>
            : Validate<Entries, object>

      Returns FetchHandler

      import { pipeline } from '@supabase/middleware'
      import { withCors } from '@supabase/middleware/cors'
      import { withFeatureFlag } from '@supabase/middleware/feature-flag'

      export default {
      fetch: pipeline(
      [
      withCors({}),
      withFeatureFlag({ name: 'beta', evaluate: (req) => req.headers.has('x-beta') }),
      ],
      async (req, ctx) => Response.json({ flag: ctx.featureFlag.name }),
      ),
      }