This project contains an example of Fedify on Cloudflare Workers. Although
it can just accept Follow and Undo(Follow) activities, it sufficiently
shows how to use Fedify on Cloudflare Workers.
The application code is placed in the src/index.ts file, and the most
important part for integration with Cloudflare Workers is the end of the file,
where the export default statement is used to export the fetch() and
queue() methods.
Here are some important notes about the code:
-
Since
KvNamespaceandQueueare not bound to global variables, but rather passed as an argument to thefetch()andqueue()methods, you need to instantiate yourFederationobject inside these methods, rather than at the top level. -
Since defining a
queue()method is the only way to consume messages from the queue in Cloudflare Workers, we need to define it so that the messages can be manually processed byFederation.processQueuedTake()method.
You can run this example in your local machine using the pnpm dev command:
pnpm install
pnpm dev