Skip to main content

aim_edge 0.3.0 copy "aim_edge: ^0.3.0" to clipboard
aim_edge: ^0.3.0 copied to clipboard

Platformweb

Run Aim web applications on Cloudflare workerd (Cloudflare Workers) compiled to WebAssembly with dart compile wasm.

aim_edge #

Run an Aim application on Cloudflare workerd (Cloudflare Workers), compiled to WebAssembly with dart compile wasm.

import 'package:aim_edge/aim_edge.dart';

void main() {
  final app = Aim();
  app.get('/', (c) async => c.text('Hello from Dart on workerd'));
  app.serveEdge();
}

serveEdge() registers globalThis.__aimFetch. A small JS entry module instantiates the wasm module on the first request and forwards fetch(request, env, ctx) to it. See examples/edge-sample in the repository for the build script, wrangler.jsonc, and the entry module.

Bindings and request metadata #

c.env returns a typed Bindings?: c.env?.string('GREETING') reads a var or secret, c.env?.get('MY_KV') returns a resource binding (KV namespace, D1 database, ...) as a raw JSObject you call with dart:js_interop, and c.env?.has('MY_KV') checks presence.

c.cf returns a typed CfProperties? for Cloudflare's request.cf metadata: c.cf?.country, c.cf?.colo, c.cf?.city, c.cf?.asn, and more.

c.executionContext is still a raw JSObject?, for waitUntil / passThroughOnException via dart:js_interop.

Middleware #

The aim_server_* middleware packages (cors, cookie, form, logger, sse, jwt, basic_auth) depend on aim_core and work unchanged on workerd. aim_server_static and aim_server_multipart's saveTo() need the file system and are VM-only.

Limitations (v1) #

  • Request bodies are read fully into memory before the handler runs.
  • Response bodies are streamed without backpressure; fast producers buffer in the JS queue.
  • serveEdge() must be called synchronously from main(); the JS entry module expects globalThis.__aimFetch to exist right after invokeMain().
  • Responses with status 101, 204, 205, or 304 are sent without a body regardless of the Dart body.
1
likes
130
points
374
downloads

Documentation

API reference

Publisher

verified publisherdart-forge.dev

Weekly Downloads

Run Aim web applications on Cloudflare workerd (Cloudflare Workers) compiled to WebAssembly with dart compile wasm.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

aim_core, web

More

Packages that depend on aim_edge