We recommend using Photon for a seamless and full-fledged Cloudflare integration.
The entire documentation for using Cloudflare with Photon is contained on this page and vike-photon.
In development, your server code runs inside workerd (the runtime Cloudflare uses in production), so you're developing in an environment similar to production. This is a new Cloudflare feature that Photon fully supports.
// wrangler.jsonc{ "$schema": "node_modules/wrangler/config-schema.json", "compatibility_date": "2025-08-06", "name": "my-vike-cloudflare-app", "main": "virtual:photon:cloudflare:server-entry", // Only required if your app (or one of your libraries) uses a Node.js API "compatibility_flags": ["nodejs_compat"]}
# .gitignore.wrangler/
4. Server (optional)
Photon includes a built-in server that supports basic features like SSR. If you need additional server functionalities (e.g. file uploads or API routes), see vike-photon > Server.
// pages/+onCreateGlobalContext.server.js// Environment: serverexport { onCreateGlobalContext }import { env } from 'cloudflare:workers'async function onCreateGlobalContext(globalContext) { // Making the environment variable LOG_LEVEL available on the client-side globalContext.logLevel = env.LOG_LEVEL || 'info'}
// pages/+onCreateGlobalContext.server.ts// Environment: serverexport { onCreateGlobalContext }import { env } from 'cloudflare:workers'import type { GlobalContextServer } from 'vike/types'async function onCreateGlobalContext(globalContext: GlobalContextServer) { // Making the environment variable LOG_LEVEL available on the client-side globalContext.logLevel = env.LOG_LEVEL || 'info'}declare global { namespace Vike { interface GlobalContext { logLevel: string } }}
You can also directly use Cloudflare Workers instead of using Cloudflare Pages.
Cloudflare Workers requires your entire worker code to be bundled into a single file — you can use Wrangler to achieve that (it uses esbuild under the hood).
Cloudflare uses the term "worker code" to denote server code that is run on its edge infrastructure.
For a significantly faster development experience we recommend, whenever possible, using Vite's development server (or a server such as Express.js or Hono) instead of Wrangler.
In other words:
Skip wrangler / Cloudflare Workers altogether while developing your app.
Use wrangler dev to preview your worker.
Use wrangler publish to deploy your worker to Cloudflare Workers.
When using Node.js(/Bun/Deno) for development and Cloudflare Workers for production, you may need a fetch() function that works in both environments.
You can define a fetch function at pageContext.fetch that works in all environments.
The trick is to add a different fetch() implementation to pageContextInit at renderPage(pageContextInit).