Overview
Cloudflare Pages is a platform for deploying static sites and full-stack applications. It provides automatic deployments from Git, preview environments, and edge computing with Pages Functions.Quick Start
Deploy a Site
Deploy a directory of static assets:<directory>- Directory containing static files--project-name- Name of the project (required for first deployment)--branch- Git branch name (defaults to current branch)--commit-hash- Git commit SHA--commit-message- Commit message to attach--commit-dirty- Mark workspace as dirty--skip-caching- Disable asset caching--no-bundle- Skip bundling_worker.js--upload-source-maps- Upload server-side source maps
Configuration
Configure Pages in your wrangler.json:wrangler.json
Project Management
Create a Project
Create a new Pages project:<project-name>- Project name (required)--production-branch- Name of production branch--compatibility-flags- Compatibility flags--compatibility-date- Compatibility date (YYYY-MM-DD)
List Projects
View all Pages projects:--json- Output as JSON
Delete a Project
Delete a Pages project:Deployment Management
List Deployments
View deployments for a project:- Deployment ID
- Environment (production/preview)
- Created timestamp
- Deployment URL
- Git commit info
Get Deployment Info
View details of a specific deployment:Tail Deployment Logs
Stream real-time logs from a deployment:--project-name- Project name--environment- Environment (production/preview)--format- Output format (json/pretty)
Pages Functions
Pages Functions enable server-side logic at the edge.Directory Structure
Function Examples
- Basic Function
- HTTP Methods
- Dynamic Routes
- Middleware
functions/api/hello.ts:Access at:
https://your-site.pages.dev/api/helloContext Object
Advanced Features
Environment Variables
Set environment variables and secrets:Access in functions:
Custom Domains
Add custom domains to your project:Example:
Download Config
Download project configuration:Downloads wrangler.json with bindings and settings.
Build Integration
Configure build settings:
wrangler.json
Development Workflow
Local Development
Run Pages locally withwrangler dev:
<directory>- Static files directory--port- Port to listen on (default: 8788)--local- Use local bindings--persist-to- Local persistence directory--live-reload- Enable auto-reload
Preview Deployments
Every non-production branch gets a preview deployment:https://<branch>.<project>.pages.dev
Production Deployments
Deploy to production branch:https://<project>.pages.dev- Custom domains (if configured)
Bindings and Resources
Pages Functions can access Workers bindings:wrangler.json
Best Practices
Project Structure
- Keep functions in
/functionsdirectory - Use
_middleware.tsfor shared logic - Organize by routes:
/api/users.ts - Static files in
/publicor build output
Performance
- Minimize function bundle size
- Use
--skip-cachingonly when needed - Enable source maps for debugging
- Cache static assets with headers
Development
- Test locally with
wrangler pages dev - Use preview deployments for testing
- Configure compatibility date/flags
- Version control wrangler.json
Security
- Use secrets for sensitive data
- Implement authentication middleware
- Validate input in functions
- Set appropriate CORS headers
Common Patterns
API Routes
API Routes
Authentication
Authentication
File Uploads
File Uploads
SSR with Framework
SSR with Framework
Limits
- Function size: 10 MB (compressed)
- Request body: 100 MB
- Execution time: 30 seconds (can be extended)
- Deployments: 500 per day
- Bandwidth: Unlimited
Related Commands
- KV Storage - Edge key-value storage
- D1 Database - SQL database
- R2 Storage - Object storage
- Durable Objects - Stateful coordination