Cloudflare Deployment
Relevant source files
The following files were used as context for generating this wiki page:
The Bolt application is built using the Remix framework and is specifically engineered for deployment on the Cloudflare ecosystem, utilizing Cloudflare Pages for hosting static assets and Cloudflare Workers (via Pages Functions) for server-side logic and API execution. This architecture enables the application to run at the edge, providing low-latency access to the global Cloudflare network while leveraging the nodejs_compat flag for compatibility with Node.js APIs.
Sources: CONTRIBUTING.md:46-48, wrangler.toml:1-5
Deployment Architecture
The deployment relies on the integration between Remix Vite builds and Cloudflare's serverless infrastructure. The build process generates two primary outputs: a client-side bundle for static hosting and a server-side bundle executed by Cloudflare's runtime.
Infrastructure Components
- Cloudflare Pages: Hosts the static production build located in
./build/client. - Cloudflare Workers/Functions: Handles dynamic requests through the
functions/[[path]].tsentry point, which serves as the bridge between the Cloudflare runtime and the Remix server build. - Wrangler: The primary CLI tool used for local development, type generation, and production deployment.
The diagram shows how the build output is partitioned between static hosting and serverless execution.
Sources: wrangler.toml:4-5, functions/[[path]].ts:1-10, package.json:10-11
Configuration and Environment
Deployment and local emulation are governed by the wrangler.toml file and the Remix load context. The project uses specific compatibility settings to ensure the Remix server functions correctly within the Cloudflare Worker environment.
Deployment Settings
| Setting | Value | Description |
|---|---|---|
name | "bolt" | The project name in the Cloudflare dashboard. |
compatibility_flags | ["nodejs_compat"] | Enables Node.js API compatibility in the edge runtime. |
compatibility_date | "2024-07-01" | Specifies the Cloudflare runtime version behavior. |
pages_build_output_dir | "./build/client" | Directory containing the final static assets. |
Sources: wrangler.toml:2-5
Runtime Context
The application extends the Remix AppLoadContext to include Cloudflare-specific properties, primarily the cloudflare object which contains environment variables and platform proxies.
Sources: load-context.ts:1-10
Build and Deployment Lifecycle
The deployment process is managed via pnpm scripts defined in package.json. It involves a multi-stage process of building the application and then pushing it to Cloudflare.
Deployment Workflow
- Build Phase: Runs
remix vite:build, which generates the server and client assets. - Deployment Phase: Uses
wrangler pages deployto upload the./build/clientdirectory to Cloudflare.
The sequence shows the transition from local build commands to a live Cloudflare deployment.
Sources: package.json:10-21, CONTRIBUTING.md:104-106
Server Entry Point
The server-side execution is initiated through functions/[[path]].ts, which uses createPagesFunctionHandler. This handler imports the server build from ../build/server (generated during the build phase) and manages incoming requests.
Sources: functions/[[path]].ts:1-10
Local Development vs. Production
To ensure parity with the Cloudflare environment, the project uses wrangler pages dev for local testing.
- Vite Dev Proxy: The
vite.config.tsincludesremixCloudflareDevProxy(), which provides an emulation of the Cloudflare environment during development. - Bindings: Local execution uses a
bindings.shscript to set up necessary environment variables and bindings, ensuring the local server behaves identically to the edge worker. - Production Build Optimization: In production mode, the build pipeline applies
optimizeCssModulesto minimize the CSS footprint.
Sources: vite.config.ts:18-21, package.json:17, CONTRIBUTING.md:78-83
Summary
Cloudflare Deployment in the Bolt project is a tightly integrated process that leverages Remix Vite builds and Wrangler. By targeting Cloudflare Pages and Workers with nodejs_compat enabled, the system ensures that the AI-powered development environment is accessible with high performance and minimal infrastructure overhead. Significant configuration is handled through wrangler.toml and the specialized functions/ entry point to bridge the gap between standard web server logic and the Cloudflare edge runtime.