Loading...
Loading...
Deploy full-stack applications on Cloudflare Pages. Covers Git integration, Direct Upload, Wrangler CLI, build configuration, Pages Functions (file-based routing), bindings, headers/redirects, custom domains, environment variables. Keywords: Cloudflare Pages, Pages Functions, Git deployment, Direct Upload, Wrangler, pages.dev, _headers, _redirects, _routes.json, preview deployments.
npx skill4agent add itechmeat/llm-code cloudflare-pagesreferences/deployment.mdreferences/build.mdreferences/functions.mdreferences/bindings.mdreferences/headers-redirects.mdreferences/domains.mdreferences/wrangler.md| Method | Best For | Limits |
|---|---|---|
| Git integration | CI/CD from GitHub/GitLab | Cannot switch to Direct Upload later |
| Direct Upload | Prebuilt assets, CI pipelines | Wrangler: 20k files, 25 MiB/file |
| C3 CLI | New project scaffolding | Framework-dependent |
# Create project
npx wrangler pages project create my-project
# Deploy
npx wrangler pages deploy ./dist
# Preview deployment (branch)
npx wrangler pages deploy ./dist --branch=feature-x# Framework presets (command → output directory)
# React (Vite): npm run build → dist
# Next.js: npx @cloudflare/next-on-pages@1 → .vercel/output/static
# Nuxt.js: npm run build → dist
# Astro: npm run build → dist
# SvelteKit: npm run build → .svelte-kit/cloudflare
# Hugo: hugo → public| Variable | Value |
|---|---|
| |
| Branch name |
| Commit SHA |
| Deployment URL |
/functions/functions/index.js → example.com/
/functions/api/users.js → example.com/api/users
/functions/users/[id].js → example.com/users/:id// functions/api/hello.js
export function onRequest(context) {
return new Response("Hello from Pages Function!");
}| Export | Trigger |
|---|---|
| All methods |
| GET only |
| POST only |
interface EventContext {
request: Request;
env: Env; // Bindings
params: Params; // Route parameters
waitUntil(promise: Promise<any>): void;
next(): Promise<Response>;
data: Record<string, any>;
}context.env| Binding | Access Pattern |
|---|---|
| KV | |
| R2 | |
| D1 | |
| Workers AI | |
For detailed binding configuration, see:skill.cloudflare-workers
_headers_redirects# _headers
/*
X-Frame-Options: DENY
/static/*
Cache-Control: public, max-age=31536000, immutable# _redirects
/old-page /new-page 301
/blog/* https://blog.example.com/:splatWarning:and_headersdo NOT apply to Pages Functions responses._redirects
_routes.json{
"version": 1,
"include": ["/api/*"],
"exclude": ["/static/*"]
}// wrangler.jsonc
{
"name": "my-pages-app",
"pages_build_output_dir": "./dist",
"compatibility_date": "2024-01-01",
"kv_namespaces": [{ "binding": "KV", "id": "<NAMESPACE_ID>" }],
"d1_databases": [{ "binding": "DB", "database_name": "my-db", "database_id": "<ID>" }]
}npx wrangler pages dev ./dist
# With bindings
npx wrangler pages dev ./dist --kv=MY_KV --d1=MY_DB=<ID>_headers_redirects_redirectswrangler.toml.dev.vars| Issue | Solution |
|---|---|
| Functions not invoked | Check |
| Headers not applied | Ensure not a Functions response; attach in code |
| Build fails | Check build command exit code (must be 0) |
| Custom domain inactive | Verify DNS CNAME points to |
| Preview URLs indexed | Default |
#!/bin/bash
if [ "$CF_PAGES_BRANCH" == "production" ]; then
npm run build:prod
else
npm run build:dev
fi404.html// _routes.json
{
"version": 1,
"include": ["/api/*"],
"exclude": ["/*"]
}cloudflare-workerscloudflare-d1cloudflare-r2cloudflare-kv