Skip to main content

Import

Examples

Single middleware

Pipeline composition

API

middlewarePipeline.use(middleware)

Add a middleware handler to the pipeline. Returns: this

middlewarePipeline.useFor(pattern, )

Add a middleware handler that only runs for matching URL patterns. Returns: this

middlewarePipeline.onTeardown(cb)

Register a cleanup callback that runs after the response is sent. Returns: this

middlewarePipeline.compose()

Compose all registered middleware into a single handler function. Returns: MiddlewareHandler

middlewarePipeline.execute(req, env, executionCtx, adapter)

Execute the pipeline for an incoming request. Returns: Promise<Response>

middlewarePipeline.handle(req, handler)

Run the middleware pipeline with a final request handler. Unlike execute, which returns a 404 when no middleware responds, handle invokes the given handler as the terminal step so middleware can add headers, validate auth, etc. before the handler runs. Returns: Promise<Response>

middlewarePipeline.teardown()

Run all registered teardown callbacks. Returns: Promise<void>

middlewarePipeline.getMiddleware()

List registered middleware with metadata. Returns: Array<{ name?: string; order?: number }>

Type Reference

CorsOptions

Options accepted by cors.

RateLimitOptions

Options accepted by rate limit.

LoggerOptions

Options accepted by logger.

TimeoutOptions

Options accepted by timeout.

Exports

Functions

Classes

Types