-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Hi everyone,
I’m experimenting with a multi-worker architecture using @opennextjs/cloudflare and Cloudflare service bindings.
Goal:
Separate CMS logic (Payload) into a dedicated worker and use it from the frontend worker without going through public HTTP endpoints. Basically: can a custom worker expose something like a Payload instance (e.g. via getPayload()) so the frontend worker can call it directly?
Context:
ServiceBindingsallow calling other workers without extra request cost- I have this working for simple functions:
export default {
fetch: handler.fetch,
foo: async (args: any) => `hello: ${args}`,
}From the frontend worker, calling CMS.foo() works fine.
Problem:
When exporting a Payload instance (from getPayload()) inside a custom worker, bundling fails because of dependencies like file-type, sharp, streams, etc — basically Node-only APIs.
Is there something I'm missing when using custom worker? Because these APIs are accessible when running with opennextjs/cloudflare dev
Question:
Is there an official / recommended way to expose something like a Payload instance (or similar complex services) between workers using the custom worker entrypoint, instead of exposing everything through HTTP routes?
Or is the intended pattern to wrap all access with fetch endpoints and avoid sharing internal services entirely?
Extra notes:
- Not talking about public REST access.
- Trying to keep bundle size small and avoid double hops (frontend → public CMS URL → DB).
Any insights from the core team or real-world examples would be appreciated.