Skip to content

Cloudflare Pages

Cloudflare Pages permet de déployer des sites statiques (Astro, Next.js, etc.) sur le réseau edge de Cloudflare avec CI/CD intégré ou via Wrangler.


  1. Concepts
  2. Prérequis
  3. Initialisation d’un projet
  4. Configuration Wrangler
  5. Déploiement manuel
  6. CI/CD avec Gitea Actions
  7. Environnements
  8. Troubleshooting

AspectPagesWorkers
UsageSites statiques, SSG, SSRAPI, fonctions serverless
BuildCôté Cloudflare ou localLocal uniquement
OutputFichiers HTML/CSS/JSCode JavaScript
Commandewrangler pages deploywrangler deploy
sequenceDiagram
    participant Dev as Développeur
    participant Gitea as Gitea
    participant Runner as Runner CI
    participant CF as Cloudflare

    Dev->>Gitea: git push main
    Gitea->>Runner: Déclenche workflow
    Runner->>Runner: bun install
    Runner->>Runner: bun run build (astro build)
    Runner->>CF: wrangler pages deploy dist
    CF->>CF: Upload des fichiers
    CF-->>Runner: URL de déploiement
    Note over CF: Disponible sur<br/>projet.pages.dev

Terminal window
# Avec bun (recommandé)
bun add -d wrangler
# Avec npm
npm install -D wrangler
Terminal window
bun wrangler login

Cette commande :

  1. Ouvre un navigateur pour l’authentification OAuth
  2. Stocke les credentials dans ~/.wrangler/config/default.toml
  3. Affiche “Successfully logged in” si réussi
Terminal window
bun wrangler whoami

Output attendu :

⛅️ wrangler 4.x.x
Getting User settings...
👋 You are logged in with an OAuth Token, associated with the email: votre@email.com

Terminal window
bun wrangler pages project create <nom-du-projet>

Exemple :

Terminal window
bun wrangler pages project create mindlet-doc

Output :

✔ Enter the production branch name: › main
✨ Successfully created the 'mindlet-doc' project.
It will be available at https://mindlet-doc.pages.dev/

Si vous avez déjà un projet Pages existant, téléchargez sa configuration :

Terminal window
bun wrangler pages download config <nom-du-projet>

Exemple :

Terminal window
bun wrangler pages download config mindlet-doc

Cela crée un fichier wrangler.toml avec la configuration du projet.


Créez wrangler.toml ou wrangler.jsonc à la racine du projet :

wrangler.toml (recommandé) :

name = "mindlet-doc"
compatibility_date = "2026-01-17"
compatibility_flags = ["nodejs_compat"]
pages_build_output_dir = "./dist"
[observability]
enabled = true
[env.production]
# Configuration spécifique à la production

wrangler.jsonc (alternative) :

{
"name": "mindlet-doc",
"compatibility_date": "2026-01-17",
"compatibility_flags": ["nodejs_compat"],
"pages_build_output_dir": "./dist",
"observability": {
"enabled": true
}
}
OptionDescriptionExemple
nameNom du projet Pages"mindlet-doc"
pages_build_output_dirDossier de build à déployer"./dist"
compatibility_dateDate de compatibilité Workers"2026-01-17"
compatibility_flagsFlags de compatibilité["nodejs_compat"]

Pour utiliser KV, D1, ou autres services :

[[kv_namespaces]]
binding = "SESSION"
id = "xxxxx"
[[d1_databases]]
binding = "DB"
database_name = "my-database"
database_id = "xxxxx"

Terminal window
bun run build

Pour Astro, cela exécute astro build et génère les fichiers dans dist/.

Méthode 1 : Avec configuration wrangler

Terminal window
bun wrangler pages deploy dist

Méthode 2 : Sans fichier de configuration

Terminal window
bun wrangler pages deploy dist --project-name=mindlet-doc
✨ Success! Uploaded 105 files (2.67 sec)
✨ Compiled Worker successfully
✨ Uploading Worker bundle
✨ Deployment complete! Take a peek over at https://abc123.mindlet-doc.pages.dev

Chaque déploiement génère une URL unique (abc123.mindlet-doc.pages.dev) en plus de l’URL de production (mindlet-doc.pages.dev).


Configurez ces secrets dans Gitea (Settings → Actions → Secrets) :

SecretDescriptionComment l’obtenir
CLOUDFLARE_API_TOKENToken API avec permissions PagesDashboard Cloudflare → API Tokens
CLOUDFLARE_ACCOUNT_IDID de votre compteDashboard → Overview → Account ID
  1. Aller sur Cloudflare Dashboard → API Tokens
  2. Cliquer Create Token
  3. Utiliser le template Edit Cloudflare Workers ou créer un custom :
    • Permissions :
      • Account → Cloudflare Pages → Edit
      • Account → Workers Scripts → Edit
    • Account Resources : Include → Votre compte
  4. Copier le token (affiché une seule fois)

Créez .gitea/workflows/deploy.yml :

name: Deploy Documentation
on:
push:
branches: [main]
jobs:
deploy:
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build
run: bun run build
- name: Deploy to Cloudflare Pages
run: bunx wrangler pages deploy dist --project-name=mindlet-doc
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

Pour déployer en staging et production :

name: CI/CD
on:
push:
branches: [main, staging]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun run build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
deploy-staging:
needs: build
if: gitea.ref == 'refs/heads/staging' && gitea.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- run: bunx wrangler pages deploy dist --project-name=mindlet-doc --branch=staging
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
deploy-production:
needs: build
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- run: bunx wrangler pages deploy dist --project-name=mindlet-doc
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

Chaque branche déployée obtient une URL unique :

  • mainmindlet-doc.pages.dev (production)
  • stagingstaging.mindlet-doc.pages.dev
  • feature-xfeature-x.mindlet-doc.pages.dev
  1. Aller dans Cloudflare Dashboard → Pages → votre projet → Custom domains
  2. Ajouter le domaine (ex: docs.mindlet.app)
  3. Configurer le DNS :
    • Type: CNAME
    • Name: docs
    • Target: mindlet-doc.pages.dev

Symptôme : Error: Project not found

Cause : Le projet n’existe pas ou le nom est incorrect.

Solution :

Terminal window
# Lister les projets existants
bun wrangler pages project list
# Créer le projet s'il n'existe pas
bun wrangler pages project create <nom>

Symptôme : Wrangler demande interactivement le projet à chaque déploiement.

Cause : Absence de fichier de configuration.

Solution :

Terminal window
# Télécharger la config depuis Cloudflare
bun wrangler pages download config <nom-du-projet>
# Ou créer manuellement wrangler.toml

Symptôme : Error: Authentication error

Cause : Token expiré ou invalide.

Solution :

Terminal window
# Se reconnecter
bun wrangler logout
bun wrangler login
# Vérifier
bun wrangler whoami

Symptôme : Le job CI échoue lors du build.

Causes possibles :

  1. Dépendances manquantes
  2. Version Node/Bun incompatible
  3. Variables d’environnement manquantes

Solution :

# Vérifier les versions dans le workflow
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest # ou une version fixe
# Ajouter les variables d'env si nécessaires
- run: bun run build
env:
PUBLIC_API_URL: ${{ vars.PUBLIC_API_URL }}

RessourceLien
Cloudflare Pages Docshttps://developers.cloudflare.com/pages/
Wrangler Commandshttps://developers.cloudflare.com/workers/wrangler/commands/
Pages Functionshttps://developers.cloudflare.com/pages/functions/
Astro + Cloudflarehttps://docs.astro.build/en/guides/deploy/cloudflare/