Skip to content

Latest commit

 

History

History
37 lines (23 loc) · 1.15 KB

File metadata and controls

37 lines (23 loc) · 1.15 KB

Experiment Single Cloudflare Worker + NextJS + Durable Objects + OpenNext

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.

Screenshot of demo using Durable Object + NextJS + OpenNext Cloudflare

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

Steps

  1. Comment out the Durable Object in the wrangler.jsonc file

  2. Build the Next.js app:

pnpm build:cf
  1. Wrap the build output entry file:
pnpm add:durable-object
  1. Uncomment the Durable Object in the wrangler.jsonc file

  2. Run the worker:

pnpm wrangler dev