Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/pages/configuration.md
1# Configuration23## wrangler.jsonc45```jsonc6{7"name": "my-pages-project",8"pages_build_output_dir": "./dist",9"compatibility_date": "2026-01-01", // Use current date for new projects10"compatibility_flags": ["nodejs_compat"],11"placement": {12"mode": "smart" // Optional: Enable Smart Placement13},14"kv_namespaces": [{"binding": "KV", "id": "abcd1234..."}],15"d1_databases": [{"binding": "DB", "database_id": "xxxx-xxxx", "database_name": "production-db"}],16"r2_buckets": [{"binding": "BUCKET", "bucket_name": "my-bucket"}],17"durable_objects": {"bindings": [{"name": "COUNTER", "class_name": "Counter", "script_name": "counter-worker"}]},18"services": [{"binding": "API", "service": "api-worker"}],19"queues": {"producers": [{"binding": "QUEUE", "queue": "my-queue"}]},20"vectorize": [{"binding": "VECTORIZE", "index_name": "my-index"}],21"ai": {"binding": "AI"},22"analytics_engine_datasets": [{"binding": "ANALYTICS"}],23"vars": {"API_URL": "https://api.example.com", "ENVIRONMENT": "production"},24"env": {25"preview": {26"vars": {"API_URL": "https://staging-api.example.com"},27"kv_namespaces": [{"binding": "KV", "id": "preview-namespace-id"}]28}29}30}31```3233## Build Config3435**Git deployment**: Dashboard → Project → Settings → Build settings36Set build command, output dir, env vars. Framework auto-detection configures automatically.3738## Environment Variables3940### Local (.dev.vars)41```bash42# .dev.vars (never commit)43SECRET_KEY="local-secret-key"44API_TOKEN="dev-token-123"45```4647### Production48```bash49echo "secret-value" | npx wrangler pages secret put SECRET_KEY --project-name=my-project50npx wrangler pages secret list --project-name=my-project51npx wrangler pages secret delete SECRET_KEY --project-name=my-project52```5354Access: `env.SECRET_KEY`5556## Static Config Files5758### _redirects59Place in build output (e.g., `dist/_redirects`):6061```txt62/old-page /new-page 301 # 301 redirect63/blog/* /news/:splat 301 # Splat wildcard64/users/:id /members/:id 301 # Placeholders65/api/* /api-v2/:splat 200 # Proxy (no redirect)66```6768**Limits**: 2,100 total (2,000 static + 100 dynamic), 1,000 char/line69**Note**: Functions take precedence7071### _headers72```txt73/secure/*74X-Frame-Options: DENY75X-Content-Type-Options: nosniff7677/api/*78Access-Control-Allow-Origin: *7980/static/*81Cache-Control: public, max-age=31536000, immutable82```8384**Limits**: 100 rules, 2,000 char/line85**Note**: Only static assets; Functions set headers in Response8687### _routes.json88Controls which requests invoke Functions (auto-generated for most frameworks):8990```json91{92"version": 1,93"include": ["/*"],94"exclude": ["/build/*", "/static/*", "/assets/*", "/*.{ico,png,jpg,css,js}"]95}96```9798**Purpose**: Functions are metered; static requests are free. `exclude` takes precedence. Max 100 rules, 100 char/rule.99100## TypeScript101102```bash103npx wrangler types --path='./functions/types.d.ts'104```105106Point `types` in `functions/tsconfig.json` to generated file.107108## Smart Placement109110Automatically optimizes function execution location based on request patterns.111112```jsonc113{114"placement": {115"mode": "smart" // Enable optimization (default: off)116}117}118```119120**How it works**: System analyzes traffic over hours/days and places function execution closer to:121- User clusters (e.g., regional traffic)122- Data sources (e.g., D1 database primary location)123124**Benefits**:125- Lower latency for read-heavy apps with centralized databases126- Better performance for apps with regional traffic patterns127128**Trade-offs**:129- Initial learning period: First requests may be slower while system optimizes130- Optimization time: Performance improves over 24-48 hours131132**When to enable**: Global apps with D1/Durable Objects in specific regions, or apps with concentrated geographic traffic.133134**When to skip**: Evenly distributed global traffic with no data locality constraints.135136## Remote Bindings (Local Dev)137138Connect local dev server to production bindings instead of local mocks:139140```bash141# All bindings remote142npx wrangler pages dev ./dist --remote143144# Specific bindings remote (others local)145npx wrangler pages dev ./dist --remote --kv=KV --d1=DB146```147148**Use cases**:149- Test against production data (read-only operations)150- Debug binding-specific behavior151- Validate changes before deployment152153**⚠️ Warning**:154- Writes affect **real production data**155- Use only for read-heavy debugging or with non-production accounts156- Consider creating separate preview environments instead157158**Requirements**: Must be logged in (`npx wrangler login`) with access to bindings.159160## Local Dev161162```bash163# Basic164npx wrangler pages dev ./dist165166# With bindings167npx wrangler pages dev ./dist --kv KV --d1 DB=local-db-id168169# Remote bindings (production data)170npx wrangler pages dev ./dist --remote171172# Persistence173npx wrangler pages dev ./dist --persist-to=./.wrangler/state/v3174175# Proxy mode (SSR frameworks)176npx wrangler pages dev -- npm run dev177```178179## Limits (as of Jan 2026)180181| Resource | Free | Paid |182|----------|------|------|183| **Functions Requests** | 100k/day | Unlimited (metered) |184| **Function CPU Time** | 10ms/req | 30s default, 5min max (Workers Paid) |185| **Function Memory** | 128MB | 128MB |186| **Script Size** | 1MB compressed | 10MB compressed |187| **Deployments** | 500/month | 5,000/month |188| **Files per Deploy** | 20,000 | 20,000 |189| **File Size** | 25MB | 25MB |190| **Build Time** | 20min | 20min |191| **Redirects** | 2,100 (2k static + 100 dynamic) | Same |192| **Header Rules** | 100 | 100 |193| **Route Rules** | 100 | 100 |194| **Subrequests** | 50/request | 10,000/request (Workers Paid) |195196**Notes**:197- Functions use Workers runtime; Workers Paid plan increases limits198- Free plan sufficient for most projects199- Static requests always free (not counted toward limits)200201[Full limits](https://developers.cloudflare.com/pages/platform/limits/)202