Skip to main content

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:
Options:
  • <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
Examples:

Configuration

Configure Pages in your wrangler.json:
wrangler.json

Project Management

Create a Project

Create a new Pages project:
Options:
  • <project-name> - Project name (required)
  • --production-branch - Name of production branch
  • --compatibility-flags - Compatibility flags
  • --compatibility-date - Compatibility date (YYYY-MM-DD)
Example:

List Projects

View all Pages projects:
Options:
  • --json - Output as JSON
Example Output:

Delete a Project

Delete a Pages project:
This permanently deletes the project and all its deployments.

Deployment Management

List Deployments

View deployments for a project:
Shows:
  • 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:
Options:
  • --project-name - Project name
  • --environment - Environment (production/preview)
  • --format - Output format (json/pretty)
Example:

Pages Functions

Pages Functions enable server-side logic at the edge.

Directory Structure

Function Examples

functions/api/hello.ts:
Access at: https://your-site.pages.dev/api/hello

Context 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 with wrangler dev:
Options:
  • <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
Example:

Preview Deployments

Every non-production branch gets a preview deployment:
Previews are available at:
  • https://<branch>.<project>.pages.dev

Production Deployments

Deploy to production branch:
Production is available at:
  • https://<project>.pages.dev
  • Custom domains (if configured)

Bindings and Resources

Pages Functions can access Workers bindings:
wrangler.json
Access in functions:

Best Practices

Project Structure

  • Keep functions in /functions directory
  • Use _middleware.ts for shared logic
  • Organize by routes: /api/users.ts
  • Static files in /public or build output

Performance

  • Minimize function bundle size
  • Use --skip-caching only 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

Limits

  • Function size: 10 MB (compressed)
  • Request body: 100 MB
  • Execution time: 30 seconds (can be extended)
  • Deployments: 500 per day
  • Bandwidth: Unlimited