This is an experiment to see how to run Durable Objects in the same worker as a Next.js app using opennext-cloudflare
.
The idea is to have a single worker that serves both the Next.js app and the Durable Object.
Warning
This is a hack; it basically wraps the build output of opennext-cloudflare
and adds a named export that points to the Durable Object class.
You won't be able to use the development server, and you'll have to build the app every time you make changes to the Next.js app.
This is based on one of the official Cloudflare Astro templates
-
Comment out the Durable Object in the
wrangler.jsonc
file -
Build the Next.js app:
pnpm build:cf
- Wrap the build output entry file:
pnpm add:durable-object
-
Uncomment the Durable Object in the
wrangler.jsonc
file -
Run the worker:
pnpm wrangler dev