Cloudflare Pages Grows a Serverless Backend

Cloudflare Pages, the company’s static-site hosting platform that reached general availability in April, is extending beyond the frontend. The platform now supports serverless functions via Cloudflare Workers, turning a Pages project into a full-stack deployment target. The workflow remains a familiar git push, but the output now includes dynamic API logic alongside static assets.

The feature ships as an open beta, available at no extra cost on existing Cloudflare plans. During the beta period, Cloudflare is collecting usage data to refine limits before the service moves to general availability, at which point pricing will align with the Workers Bundled plan.

Functions via the Filesystem

The integration follows a simple convention: create a ./functions directory in the project root and export a function handler from a JavaScript or TypeScript file within it. Pages maps each file’s pathname to a corresponding URL route during the build. The build pipeline traverses the directory and compiles the handlers into Workers that manage routing and execution.

Beyond basic routes, the system supports deeply nested paths, wildcards, and middleware for concerns like authentication and error handling. The generated Workers are first-class, meaning features available to standard HTTP Workers are available to Pages functions without loss of functionality.

For projects that already run as a standalone Worker, Pages accepts an ES module Worker named _worker.js in the output directory. This path suits framework authors or use cases that don’t conform to the file-based structure above; a build step that emits this file is all that’s required before a git push.

Server-Side Rendering and Dynamic Data

With functions in place, Pages can intercept any incoming request rather than serving a static file. A Worker can render fresh HTML from dynamic data sources on each request. For a product catalog, a single product/[id].js file can fetch item data from a KV binding and render the response, replacing the need to pre-generate static pages for every product at build time. This approach is easier to maintain as content changes and does not grow with the number of pages.

Bindings and Configuration

Pages projects can attach the same bindings available to standard Workers. In the current beta, that includes:

  • KV namespace — global key-value storage that can reference namespaces defined in the Workers dashboard.
  • Durable Object namespace — strongly consistent coordination for WebSocket connections and state, selectable from the dashboard and then used in a Pages project.
  • Environment variables — plaintext values injected at build time and runtime, configurable separately for production and preview environments.

Two additional bindings are on the roadmap: R2, the S3-compatible object storage service, and Secrets, which store encrypted values not visible in dashboards or to the Wrangler CLI.

Preview Environments Cover the Full Stack

Because deployments are triggered by git push, the usual Pages preview workflow now extends to backend code. Each commit generates a unique URL, so functions can be tested and reviewed in staging before a merge promotes the change to production. Preview environments are unlimited, and the latest commit to a preview branch gets a consistent URL.

For quick iteration, the latest Wrangler CLI also runs full-stack Pages applications locally. The local runtime, built on Miniflare, supports static assets alongside mocked secrets, environment variables, and KV. Durable Object support for the local dev server is still in progress.

Framework Support: SvelteKit First

SvelteKit projects can now attach the @sveltejs/adapter-cloudflare package and deploy directly to Pages. This enables API endpoints and full server-side rendering support, with preview deployments covering the API routes alongside the frontend. The setup applies to advanced SvelteKit applications that previously relied on the Workers adapter, and Cloudflare points to an example repository demonstrating the pattern in action.

Future work is planned for similar first-class integrations with NextJS, NuxtJS, React Server Components, Shopify Hydrogen, and Remix. That work, along with improvements to build times, is part of the roadmap for the beta period.

Getting Started

The full technical details on file structure, route mapping, and bindings are available in the Pages documentation on Cloudflare Developers. A separate demo blog walks through building a full-stack application with these features.