Local Development
Local Development
Shapeless uses OpenNextJS to support full monolithic deployment to Cloudflare Workers. That means you can develop locally using either the regular Next.js dev server, or emulate the actual Cloudflare environmentβall from a single process.
π Standard Dev Mode (Node.js)
Start the app with:
pnpm dev
# or
bun dev
# or
npm run dev
This runs the regular Next.js development server on:
http://localhost:3000
It uses Node.js, so it's fast and has full support for React features like HMR, fast refresh, etc.
Use this when you're building UI and want a quick feedback loop.
π Cloudflare Workers Preview Mode
To test how your app will behave on Cloudflare (with the Workers runtime and bindings like D1
, R2
, etc.), run:
pnpm run cf:gen # optional, generates env typings
pnpm run cf:preview
This starts your app in Cloudflare Workers preview mode:
http://localhost:8788
This simulates the production environment using Wrangler and OpenNextJS.
This mode is recommended when you need to test Cloudflare-specific behavior like:
- Worker compatibility (
globalThis
, fetch, etc.)- Database bindings (D1)
- Storage bindings (R2)
- Compatibility flags (
nodejs_compat
, etc.)
β API Client Config
Update your API client to match the preview mode when needed:
// src/shapeless.client.ts
export const client = createClient<AppRouter>({
baseUrl: "http://localhost:8788/api", // if using cf:preview
})
You can also make this dynamic with an .env.local
:
baseUrl: process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:3000/api"
And then in .env.local
:
NEXT_PUBLIC_API_URL=http://localhost:8788/api
π Available Scripts
From your package.json
:
{
"dev": "next dev",
"cf:preview": "opennextjs-cloudflare preview",
"cf:build": "opennextjs-cloudflare build",
"cf:upload": "opennextjs-cloudflare build && opennextjs-cloudflare upload",
"cf:gen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts"
}
dev
: regular Next.js dev server (Node.js)cf:preview
: run app on local Cloudflare worker runtimecf:build
: compile the app for Workerscf:upload
: deploy to production Cloudflarecf:gen
: generate Cloudflare bindings types
π§ͺ When to Use Each Mode
Goal | pnpm dev | pnpm cf:preview |
---|---|---|
Building UI quickly | β | β |
Testing D1 / R2 bindings | β | β |
Emulating production behavior | β | β |
Debugging layout / React | β | β |
Thatβs it β no dual terminal setup, no separate backend.
Shapeless + OpenNext = monolithic, edge-ready development, with full support for both Next.js DX and Cloudflare production behavior.