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 }),
),
}
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
ctxis 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 onentries.Under the hood,
pipelinefolds the array into the same nested calls as nested handlers — there is no new runtime behavior.