Middleware: 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 nested handlers — there is no new runtime behavior.

Parameters

Examples

Example 1

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 }),
  ),
}