Cloudflare Pages adalah platform static hosting dari Cloudflare dengan keunggulan utama: unlimited bandwidth gratis dan edge network terbesar di dunia. Artikel ini akan memandu Anda deploy Sitemas ke Cloudflare Pages.

Mengapa Cloudflare Pages?

FiturKeterangan
Free TierUnlimited bandwidth, 500 builds/month
Edge Network300+ lokasi global
SpeedSangat cepat (edge network terbesar)
IntegrationSeamless dengan Cloudflare DNS, Workers, KV
SSLOtomatis dan gratis
AnalyticsWeb Analytics gratis
Unlimited Bandwidth!

Berbeda dengan Vercel dan Netlify yang membatasi 100GB/bulan, Cloudflare Pages memberikan bandwidth unlimited bahkan di free tier.

Persiapan

Sebelum mulai:

  • ✅ Akun Cloudflare (gratis)
  • ✅ Repository di GitHub atau GitLab
  • ✅ Proyek Sitemas yang sudah bisa di-build

Deploy via Dashboard

Akses Cloudflare Pages

  1. Login ke dash.cloudflare.com
  2. Pilih akun Anda
  3. Klik Workers & Pages di sidebar
  4. Klik Create applicationPagesConnect to Git

Connect Git Repository

  1. Pilih GitHub atau GitLab
  2. Authorize Cloudflare
  3. Pilih repository Sitemas
  4. Klik Begin setup

Configure Build

SettingValue
Project namesitemas-blog (atau nama lain)
Production branchmain
Framework presetAstro
Build commandnpm run build
Build output directorydist

Environment Variables

Expand Environment variables (advanced):

VariableValue
NODE_VERSION20
PUBLIC_SITE_URLhttps://yourdomain.com

Save and Deploy

Klik Save and Deploy. Tunggu build selesai (2-5 menit).

Website live di: https://projectname.pages.dev

Deploy via Wrangler CLI

Install Wrangler

Install Wrangler CLI
npm install -g wrangler

Login

Login ke Cloudflare
wrangler login

Browser akan terbuka untuk autentikasi.

Build Project

Build locally
npm run build

Deploy

Deploy ke Pages
wrangler pages deploy dist

Pilih project name dan branch saat diminta.

Konfigurasi wrangler.toml (Opsional)

Untuk project dengan Workers atau advanced config:

wrangler.toml
toml
name = "sitemas-blog"
compatibility_date = "2024-01-01"

[site]
bucket = "./dist"

Konfigurasi _headers

Buat file public/_headers untuk custom headers:

public/_headers
text
# Cache static assets
/fonts/*
  Cache-Control: public, max-age=31536000, immutable

/_astro/*
  Cache-Control: public, max-age=31536000, immutable

# Security headers
/*
  X-Frame-Options: DENY
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=()

Konfigurasi _redirects

Buat file public/_redirects untuk redirects:

public/_redirects
text
# Redirect old URLs
/old-page /new-page 301

# Force HTTPS
http://yourdomain.com/* https://yourdomain.com/:splat 301

# www to non-www
https://www.yourdomain.com/* https://yourdomain.com/:splat 301

Custom Domain

Tambah Custom Domain

  1. Buka project di Pages dashboard
  2. Klik Custom domains tab
  3. Klik Set up a custom domain
  4. Masukkan domain: yourdomain.com

Konfigurasi DNS

Jika domain sudah di Cloudflare:

  • DNS akan otomatis dikonfigurasi
  • SSL langsung aktif

Jika domain di luar Cloudflare:

# CNAME record
Type: CNAME
Name: @ atau www
Target: projectname.pages.dev

Atau transfer domain ke Cloudflare untuk experience terbaik.

Aktifkan www Redirect

Tambahkan www.yourdomain.com juga, lalu set redirect di _redirects.

Environment Variables

Production vs Preview

VariableProductionPreview
PUBLIC_SITE_URLhttps://yourdomain.comhttps://preview.pages.dev
NODE_ENVproductionproduction

Menambahkan Variables

  1. SettingsEnvironment variables
  2. Pilih Production atau Preview
  3. Add variable
Rebuild Required

Setelah mengubah environment variables, Anda perlu trigger redeploy agar perubahan berlaku.

Preview Deployments

Setiap push ke branch non-production mendapat preview URL:

https://[commit-hash].projectname.pages.dev

Untuk Pull Requests:

https://[pr-number].projectname.pages.dev

Cloudflare Web Analytics

Gratis dan privacy-friendly:

  1. Buka Web Analytics di Cloudflare dashboard
  2. Add site
  3. Copy snippet ke BaseLayout.astro:
Cloudflare Analytics
html
<!-- Cloudflare Web Analytics -->
<script 
    defer 
    src='https://static.cloudflareinsights.com/beacon.min.js' 
    data-cf-beacon='{"token": "YOUR_TOKEN"}'
></script>

Integrasi dengan Cloudflare Ecosystem

Cloudflare R2 (Storage)

Untuk media files besar, gunakan R2:

// Di Astro, akses via binding
const object = await env.MY_BUCKET.get('image.jpg');

Cloudflare KV (Key-Value)

Untuk data yang perlu diakses di edge:

const value = await env.MY_KV.get('key');

Cloudflare D1 (Database)

SQLite at the edge:

const { results } = await env.DB.prepare(
    'SELECT * FROM articles'
).all();

Troubleshooting

Build Gagal

ErrorSolusi
Node versionSet NODE_VERSION = 20 di env vars
Out of memoryOptimize build atau upgrade plan
Module not foundCek dependencies dan import paths

Deployment Pending

Build queue bisa panjang di jam sibuk. Tunggu atau upgrade ke Pro.

404 pada Routes

Pastikan:

  • dist folder berisi semua halaman
  • Dynamic routes punya getStaticPaths()

SSL Issues

Jika menggunakan external DNS:

  • Pastikan proxy status Proxied (orange cloud)
  • Tunggu SSL provisioning (bisa sampai 24 jam)

Perbandingan Platform

AspekCloudflareVercelNetlify
Free bandwidthUnlimited100GB100GB
Free builds500/month6000300
Edge locations300+70+Limited
DNS integration✅ Native
DDoS protection✅ FreeLimitedLimited

Best Practices

  1. Gunakan Cloudflare DNS untuk fastest propagation
  2. Enable Web Analytics untuk tracking
  3. Set proper cache headers untuk static assets
  4. Use R2 untuk media hosting jika traffic tinggi
  5. Monitor build minutes (500/month free)

Langkah Selanjutnya

Pelajari cara setup custom domain:

Custom Domain

Pelajari cara menghubungkan domain sendiri dan konfigurasi SSL.

Kesimpulan

Cloudflare Pages adalah pilihan terbaik jika:

  • Traffic tinggi (unlimited bandwidth)
  • Performa prioritas (edge network terbesar)
  • Sudah menggunakan Cloudflare untuk DNS/CDN
  • Butuh integrasi dengan Workers, KV, R2, D1

Deploy Sitemas ke Cloudflare Pages hanya butuh beberapa menit, dan Anda mendapat performa enterprise-grade secara gratis.