This is a Next.js pre-configured to run on Cloudflare using @opennextjs/cloudflare.
Try it out: Live Demo
Note that I use yarn in this README, but you can remove yarn.lock and use npm, pnpm, or bun if you like
Update worker-configuration.d.ts by running:
cd worker && yarn cf-typegenLeave the Durable Object Worker running. It serves as a local WebSocket server:
yarn devRun Next.js development server from root directory (the Durable Object server must also be running):
First, copy .env.example to .env.local
cp .env.example .env.localThen, run:
yarn devOpen http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.
Before deploying, log in with your Cloudflare account by running:
npx wrangler loginYou will be directed to a web page asking you to log in to the Cloudflare dashboard. After you have logged in, you will be asked if Wrangler can make changes to your Cloudflare account. Scroll down and select Allow to continue.
Change into your Durable Object Worker directory:
cd workerDeploy the Worker:
yarn deployCopy only the host from the generated Worker URL, excluding the protocol, and set NEXT_PUBLIC_WS_HOST in .env.local to this value (e.g., worker-unique-identifier.workers.dev).
Change into your root directory and deploy your Next.js app:
yarn deployOr connect a Github or Gitlab repository, and Cloudflare will automatically build and deploy each pull request you merge to your production branch.
If you found this useful and would like to join my free AI builders community: Discord