Skip to main content
Module

x/keywork/mod.ts>Middleware.ServiceBindingRouter

A library for building V8 Isolate web apps on Cloudflare Workers, Deno, and Node.JS
Go to Latest
class Middleware.ServiceBindingRouter
extends KeyworkRouter<Record<BindingAlias, WorkerEnvFetchBinding>>
Re-export
import { Middleware } from "https://deno.land/x/keywork@v6.0.1/mod.ts";
const { ServiceBindingRouter } = Middleware;

A router that proxies requests directly to a Cloudflare Worker environment binding, such as a service binding.

Middleware in Keywork can also be thought of as any object that implements the Keywork#Router.Fetcher | Fetcher interface. Under the hood, Keywork#Router.KeyworkRouter | KeyworkRouter is a Fetcher, and is the most common usage of middleware.

Cloudflare's concept of "environment bindings" almost satisfy the Fetcher interface, and with the help of the ServiceBindingRouter class, they can be used as middleware within Keywork!

Combining Multiple Workers

The ServiceBindingRouter class proxies requests directly to an environment binding, such as a service binding configured in your project's wrangler.toml, allowing you to compose your app from multiple Workers, regardless if they use Keywork or not.

Constructors

new
ServiceBindingRouter(bindingAlias: BindingAlias, options?: KeyworkRouterOptions)

Type Parameters

BindingAlias extends string

Properties

private
onRequest: RouteRequestHandler<Record<BindingAlias, WorkerEnvFetchBinding>>