File
Blob: samples/durable-objects-chat/config.capnp
| 1 | # This is the edge chat demo found at: |
| 2 | # |
| 3 | # https://github.com/cloudflare/workers-chat-demo |
| 4 | |
| 5 | using Workerd = import "/workerd/workerd.capnp"; |
| 6 | |
| 7 | # A constant of type `Workerd.Config` will be recognized as the top-level configuration. |
| 8 | const config :Workerd.Config = ( |
| 9 | # We have one nanoservice: the chat worker. |
| 10 | services = [ (name = "chat", worker = .chatWorker) ], |
| 11 | |
| 12 | # We export it via HTTP on port 8080. |
| 13 | sockets = [ ( name = "http", address = "*:8080", http = (), service = "chat" ) ], |
| 14 | ); |
| 15 | |
| 16 | # For legibility we define the Worker's config as a separate constant. |
| 17 | const chatWorker :Workerd.Worker = ( |
| 18 | # All Workers must declare a compatibility date, which ensures that if `workerd` is updated to |
| 19 | # a newer version with breaking changes, it will emulate the API as it existed on this date, so |
| 20 | # the Worker won't break. |
| 21 | compatibilityDate = "2023-02-28", |
| 22 | |
| 23 | # This worker is modules-based. |
| 24 | modules = [ |
| 25 | # Our code is in an ES module (JavaScript). |
| 26 | (name = "chat.js", esModule = embed "chat.js"), |
| 27 | |
| 28 | # We also have an HTML file containing the client side of the app. We embed this as a text |
| 29 | # module, so that it can be served to the client. |
| 30 | (name = "chat.html", text = embed "chat.html"), |
| 31 | ], |
| 32 | |
| 33 | # The Worker has two Durable Object classes, each of which needs an attached namespace. |
| 34 | # The `uniqueKey`s can be any string, and are used to generate IDs. Keep the keys secret if you |
| 35 | # don't want clients to be able to forge valid IDs -- or don't, if you don't care about that. |
| 36 | # |
| 37 | # In the example here, we've generated 32-character random hex keys, but again, the string can |
| 38 | # be anything. These were generated specifically for this demo config; we do not use these |
| 39 | # values in production. |
| 40 | durableObjectNamespaces = [ |
| 41 | (className = "ChatRoom", uniqueKey = "210bd0cbd803ef7883a1ee9d86cce06e"), |
| 42 | (className = "RateLimiter", uniqueKey = "b37b1c65c4291f3170033b0e9dd30ee1"), |
| 43 | ], |
| 44 | |
| 45 | # To use Durable Objects we must declare how they are stored. |
| 46 | # |
| 47 | # As of this writing, `workerd` supports in-memory-only Durable Objects -- so, not really |
| 48 | # "durable", as all data is lost when workerd restarts. However, this still allows us to run the |
| 49 | # chat demo for testing purposes. (We plan to add actual storage for Durable Objects eventually, |
| 50 | # but the storage system behind Cloudflare Workers is inherently tied to our network so did not |
| 51 | # make sense to release as-is.) |
| 52 | durableObjectStorage = (inMemory = void), |
| 53 | |
| 54 | # We must declare bindings to allow us to call back to our own Durable Object namespaces. These |
| 55 | # show up as properties on the `env` object passed to `fetch()`. |
| 56 | bindings = [ |
| 57 | (name = "rooms", durableObjectNamespace = "ChatRoom"), |
| 58 | (name = "limiters", durableObjectNamespace = "RateLimiter"), |
| 59 | ], |
| 60 | ); |
| 61 |