https://github.com/exectx/exp-cloudflare-nextjs-opennext-durable-objects
https://github.com/exectx/exp-cloudflare-nextjs-opennext-durable-objects
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/exectx/exp-cloudflare-nextjs-opennext-durable-objects
- Owner: exectx
- Created: 2025-02-20T03:19:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-20T03:24:48.000Z (over 1 year ago)
- Last Synced: 2025-02-20T04:27:11.791Z (over 1 year ago)
- Language: TypeScript
- Size: 229 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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.

> [!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](https://github.com/cloudflare/templates/blob/3ecfc97322d771cda2c2428cacdc1b5cf916e6e0/saas-admin-template/package.json#L57)
## Steps
1. Comment out the Durable Object in the `wrangler.jsonc` file
2. Build the Next.js app:
```bash
pnpm build:cf
```
3. Wrap the build output entry file:
```bash
pnpm add:durable-object
```
4. Uncomment the Durable Object in the `wrangler.jsonc` file
5. Run the worker:
```bash
pnpm wrangler dev
```