Diffinery

homeflare/celldpublic

21 lines · 870 BRaw History
1# Facets
2
3This example starts a Worker at runtime with the Worker Loader, and it runs a
4Durable Object class from that Worker as a facet of a Durable Object. The facet
5counts the requests in its own SQLite database with the synchronous KV API, and
6celld replicates that database with the root object. The parent passes a
7parameterized `ctx.exports` Service Binding through `WorkerCode.env`, so the
8loaded Worker can call the parent entrypoint.
9
10The `worker_loaders` key of `wrangler.jsonc` declares the Worker Loader, and
11the entry in this example puts the binding at `env.LOADER`. Cloudflare can
12still change the Worker Loader API, so this example needs no setting but it can
13change. Start the example:
14
15```sh
16celld dev .
17curl http://127.0.0.1:9876/
18```
19
20Each request answers the count and the parent entrypoint's greeting. The count
21survives a restart of the command.