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?
| Fitur | Keterangan |
|---|---|
| Free Tier | Unlimited bandwidth, 500 builds/month |
| Edge Network | 300+ lokasi global |
| Speed | Sangat cepat (edge network terbesar) |
| Integration | Seamless dengan Cloudflare DNS, Workers, KV |
| SSL | Otomatis dan gratis |
| Analytics | Web Analytics gratis |
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
- Login ke dash.cloudflare.com
- Pilih akun Anda
- Klik Workers & Pages di sidebar
- Klik Create application → Pages → Connect to Git
Connect Git Repository
- Pilih GitHub atau GitLab
- Authorize Cloudflare
- Pilih repository Sitemas
- Klik Begin setup
Configure Build
| Setting | Value |
|---|---|
| Project name | sitemas-blog (atau nama lain) |
| Production branch | main |
| Framework preset | Astro |
| Build command | npm run build |
| Build output directory | dist |
Environment Variables
Expand Environment variables (advanced):
| Variable | Value |
|---|---|
NODE_VERSION | 20 |
PUBLIC_SITE_URL | https://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
Login
Browser akan terbuka untuk autentikasi.
Build Project
Deploy
Pilih project name dan branch saat diminta.
Konfigurasi wrangler.toml (Opsional)
Untuk project dengan Workers atau advanced config:
name = "sitemas-blog"
compatibility_date = "2024-01-01"
[site]
bucket = "./dist" Konfigurasi _headers
Buat file public/_headers untuk custom headers:
# 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:
# 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
- Buka project di Pages dashboard
- Klik Custom domains tab
- Klik Set up a custom domain
- 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.devAtau 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
| Variable | Production | Preview |
|---|---|---|
PUBLIC_SITE_URL | https://yourdomain.com | https://preview.pages.dev |
NODE_ENV | production | production |
Menambahkan Variables
- Settings → Environment variables
- Pilih Production atau Preview
- Add variable
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:
- Buka Web Analytics di Cloudflare dashboard
- Add site
- Copy snippet ke
BaseLayout.astro:
<!-- 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
| Error | Solusi |
|---|---|
Node version | Set NODE_VERSION = 20 di env vars |
Out of memory | Optimize build atau upgrade plan |
Module not found | Cek dependencies dan import paths |
Deployment Pending
Build queue bisa panjang di jam sibuk. Tunggu atau upgrade ke Pro.
404 pada Routes
Pastikan:
distfolder 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
| Aspek | Cloudflare | Vercel | Netlify |
|---|---|---|---|
| Free bandwidth | Unlimited | 100GB | 100GB |
| Free builds | 500/month | 6000 | 300 |
| Edge locations | 300+ | 70+ | Limited |
| DNS integration | ✅ Native | ❌ | ✅ |
| DDoS protection | ✅ Free | Limited | Limited |
Best Practices
- Gunakan Cloudflare DNS untuk fastest propagation
- Enable Web Analytics untuk tracking
- Set proper cache headers untuk static assets
- Use R2 untuk media hosting jika traffic tinggi
- 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.