defineCloudflareFetchFactoryWithEnvironmentAsync function

void defineCloudflareFetchFactoryWithEnvironmentAsync(
  1. Future<Engine> factory(
    1. CloudflareEnvironment environment
    )
)

Installs a lazy Cloudflare Fetch entry whose engine is built with the Worker environment and its typed D1, KV, R2, or secret bindings.

The factory runs once per Worker isolate, on the first request. The environment is wrapped before it reaches application code, so Cloudflare applications do not need to use package:web or JS interop directly.

Implementation

void defineCloudflareFetchFactoryWithEnvironmentAsync(
  Future<Engine> Function(CloudflareEnvironment environment) factory,
) {
  defineFetchExportFactoryWithEnvironmentAsync('Cloudflare', (environment) {
    if (environment == null) {
      throw StateError('Cloudflare Worker environment was not provided.');
    }
    return factory(
      cloudflare_bindings.cloudflareEnvironmentFromJavaScript(environment),
    );
  }, capabilities: cloudflareCapabilities);
}