Skip to content

Commit 7844b3a

Browse files
lawvsInnei
andauthored
docs: add Cloudflare Pages deployment guide (#162)
Co-authored-by: Innei <tukon479@gmail.com>
1 parent 1cdab98 commit 7844b3a

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

apps/docs/contents/deployment/cloudflare-pages.mdx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Cloudflare Pages
3-
description: Deploy your gallery to Cloudflare Pages for fast global CDN distribution.
3+
description: Guide to deploying Afilmory via Cloudflare Pages.
44
createdAt: 2025-07-20T22:35:03+08:00
55
lastModified: 2025-11-23T19:40:52+08:00
66
order: 53
@@ -12,10 +12,20 @@ Cloudflare Pages provides fast, global static hosting with excellent CDN perform
1212

1313
## Prerequisites
1414

15+
You need to upload your images to an OSS (Object Storage Service) like AWS S3 or Cloudflare R2 before deploying.
16+
1517
- Cloudflare account (free tier available)
1618
- GitHub or GitLab repository
1719
- Photos processed with builder
1820

21+
## Quick Deploy
22+
23+
Run the following command to build and deploy your application to Cloudflare Pages:
24+
25+
```bash
26+
pnpm --filter=@afilmory/web deploy:cloudflare
27+
```
28+
1929
## Deployment Steps
2030

2131
### Step 1: Connect Repository
@@ -28,13 +38,15 @@ Cloudflare Pages provides fast, global static hosting with excellent CDN perform
2838
### Step 2: Configure Build Settings
2939

3040
**Build configuration:**
41+
3142
- **Framework preset**: Vite
3243
- **Build command**: `pnpm run build:manifest && pnpm --filter web build`
3344
- **Build output directory**: `apps/web/dist`
3445
- **Root directory**: (leave empty, or set to project root)
3546

3647
**Environment variables:**
3748
Add your storage credentials:
49+
3850
```
3951
S3_ACCESS_KEY_ID=your_key
4052
S3_SECRET_ACCESS_KEY=your_secret
@@ -71,6 +83,7 @@ cwd = "."
7183
Set in Cloudflare Dashboard → Pages → Your Project → Settings → Environment Variables:
7284

7385
**Storage (S3 example):**
86+
7487
```
7588
S3_ACCESS_KEY_ID
7689
S3_SECRET_ACCESS_KEY
@@ -79,6 +92,7 @@ S3_REGION
7992
```
8093

8194
**Production vs Preview:**
95+
8296
- Set different variables for Production and Preview environments
8397
- Useful for testing with different storage buckets
8498

@@ -93,6 +107,7 @@ S3_REGION
93107
## Continuous Deployment
94108

95109
Cloudflare Pages automatically:
110+
96111
- **Production**: Deploys on push to main/master
97112
- **Preview**: Creates preview deployments for pull requests
98113

@@ -101,6 +116,7 @@ Each deployment gets a unique URL.
101116
## Performance Features
102117

103118
Cloudflare Pages provides:
119+
104120
- **Global CDN**: Fast delivery worldwide
105121
- **Automatic compression**: Gzip and Brotli
106122
- **Image optimization**: Automatic image optimization (Pro plan)
@@ -109,6 +125,7 @@ Cloudflare Pages provides:
109125
## Build Limits
110126

111127
Free tier limits:
128+
112129
- **Build time**: 20 minutes per build
113130
- **Builds per month**: 500
114131
- **Bandwidth**: 500 requests/second
@@ -118,24 +135,43 @@ Upgrade to Pro for higher limits.
118135
## Troubleshooting
119136

120137
**Build failures:**
138+
121139
- Check build logs in Cloudflare Dashboard
122140
- Verify all environment variables are set
123141
- Ensure `builder.config.ts` is correct
124142
- Check storage credentials
125143

126144
**Missing photos:**
145+
127146
- Verify thumbnails and manifest are in build output
128147
- Check file paths are correct
129148
- Ensure storage is accessible during build
130149

131150
**Slow builds:**
151+
132152
- Use repo cache plugin to avoid full rebuilds
133153
- Optimize storage access
134154
- Consider reducing photo count
135155

156+
## Limitations
157+
158+
Deploying the `web` app directly to Cloudflare Pages results in a static site. This means you will lose server-side features provided by the `ssr` application (Next.js), such as:
159+
160+
- **Dynamic Open Graph (OG) Images**: Social media preview cards will not be generated dynamically.
161+
162+
- **Share/Iframe Support**: Specific sharing functionality that relies on server-side rendering may not work as expected.
163+
164+
To support these features on Cloudflare, you would need to deploy the `ssr` application using a Cloudflare Workers adapter for Next.js (e.g., `@opennextjs/cloudflare`), which adds significant complexity to the deployment process.
165+
136166
## Next Steps
137167

138168
- Configure custom domain
139169
- Set up monitoring
140170
- Optimize build performance
141171
- Review [Cloudflare Pages documentation](https://developers.cloudflare.com/pages)
172+
173+
## Learn more
174+
175+
- [Commands - Wrangler](https://developers.cloudflare.com/workers/wrangler/commands/#deploy-1)
176+
177+
- [Deploy a Next.js project on Workers - Cloudflare Docs](https://developers.cloudflare.com/workers/framework-guides/web-apps/nextjs/)

apps/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"analyze": "analyzer=1 vite build",
1212
"build": "tsx scripts/build.ts",
1313
"build:serve": "BUILD_FOR_SERVER_SERVE=1 vite build",
14+
"deploy:cloudflare": "pnpm build && pnpx wrangler pages deploy",
1415
"dev": "tsx scripts/dev.ts",
1516
"format": "prettier --write \"src/**/*.ts\" ",
1617
"lint": "eslint --fix",

0 commit comments

Comments
 (0)