Skip to content

Commit c652198

Browse files
committed
Configure separate preview and production domains
This change establishes clear separation between staging and production deployments using different Cloudflare Pages branches and custom domains: Changes: - Update release-web.yml to deploy to 'release' branch (not 'main') - Add preview.cambeerfestival.app to worker CORS origins - Update documentation to reflect new architecture Architecture: - Production: cambeerfestival.app (CF Pages 'release' branch, deployed on git tags) - Preview: preview.cambeerfestival.app (CF Pages 'main' branch, deployed on git main) - PR Previews: <branch>.cambeerfestival.pages.dev (CF Pages '<branch>' branch) Next step: Configure custom domains in Cloudflare Dashboard to point: - cambeerfestival.app → release branch - preview.cambeerfestival.app → main branch
1 parent 9c0202a commit c652198

4 files changed

Lines changed: 55 additions & 19 deletions

File tree

.github/workflows/release-web.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ jobs:
8282
with:
8383
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
8484
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
85-
command: pages deploy build/web --project-name=cambeerfestival --branch=main
85+
command: pages deploy build/web --project-name=cambeerfestival --branch=release

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
A Flutter app for browsing beers, ciders, meads, and more at the Cambridge Beer Festival.
77

88
**Production**: [https://cambeerfestival.app](https://cambeerfestival.app)
9-
**Staging**: [https://richardthe3rd.github.io/cambridge-beer-festival-app/](https://richardthe3rd.github.io/cambridge-beer-festival-app/)
9+
**Preview**: [https://preview.cambeerfestival.app](https://preview.cambeerfestival.app)
10+
**Development**: [https://richardthe3rd.github.io/cambridge-beer-festival-app/](https://richardthe3rd.github.io/cambridge-beer-festival-app/)
1011

1112
## Features
1213

@@ -140,23 +141,25 @@ The app is deployed to multiple environments:
140141

141142
- **Production** (Cloudflare Pages): [cambeerfestival.app](https://cambeerfestival.app)
142143
- Deployed on version tags (e.g., `v2025.12.0`)
144+
- Uses Cloudflare Pages `release` branch
143145
- Workflow: `.github/workflows/release-web.yml`
144-
- **Staging** (Cloudflare Pages): `main.cambeerfestival.pages.dev`
145-
- Stable preview environment
146+
- **Preview/Staging** (Cloudflare Pages): [preview.cambeerfestival.app](https://preview.cambeerfestival.app)
147+
- Stable staging environment
146148
- Deployed automatically on push to `main`
149+
- Uses Cloudflare Pages `main` branch
147150
- Workflow: `.github/workflows/build-deploy.yml` (deploy-web-preview job)
148151
- **Development** (GitHub Pages): [richardthe3rd.github.io/cambridge-beer-festival-app](https://richardthe3rd.github.io/cambridge-beer-festival-app/)
149152
- Alternative development environment
150153
- Deployed automatically on push to `main`
151154
- Workflow: `.github/workflows/build-deploy.yml` (deploy-web job)
152155
- **PR Previews** (Cloudflare Pages): Unique URL per pull request
153-
- Each PR gets its own preview environment
156+
- Each PR gets its own preview environment (e.g., `<branch-name>.cambeerfestival.pages.dev`)
154157
- Preview URL posted as comment on the PR
155158
- Workflow: `.github/workflows/build-deploy.yml` (deploy-web-preview job)
156159

157160
### Deployment Strategy
158161

159-
1. **Development changes**: Push to `main`Staging (Cloudflare) + GitHub Pages updated
162+
1. **Development changes**: Push to `main`Preview (Cloudflare) + GitHub Pages updated
160163
2. **PR reviews**: Open PR → Unique Cloudflare Pages preview created
161164
3. **Production releases**: Create tag (e.g., `v2025.12.0`) → Production deployment to cambeerfestival.app
162165

cloudflare-worker/worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const FESTIVALS_CACHE_CONTROL = 'no-cache, must-revalidate';
2222
const ALLOWED_ORIGINS = [
2323
'https://richardthe3rd.github.io',
2424
'https://cambeerfestival.app',
25+
'https://preview.cambeerfestival.app',
2526
'http://localhost:8080',
2627
'http://localhost:3000',
2728
'http://127.0.0.1:8080',

docs/CLOUDFLARE_PAGES_SETUP.md

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ This document explains how to set up Cloudflare Pages deployment for the Cambrid
88
99
## Overview
1010

11-
The app has two deployment targets:
11+
The app has three deployment targets:
1212

13-
1. **GitHub Pages** (Development/Staging): `richardthe3rd.github.io/cambridge-beer-festival-app/`
14-
2. **Cloudflare Pages** (Production): `cambeerfestival.app`
13+
1. **GitHub Pages** (Development): `richardthe3rd.github.io/cambridge-beer-festival-app/`
14+
2. **Cloudflare Pages Staging** (Preview): `preview.cambeerfestival.app`
15+
3. **Cloudflare Pages Production**: `cambeerfestival.app`
16+
17+
### Deployment Architecture
18+
19+
| Git Event | Cloudflare Pages Branch | Custom Domain | Purpose |
20+
|-----------|------------------------|---------------|---------|
21+
| Pull Request | `<branch-name>` | `<branch-name>.cambeerfestival.pages.dev` | PR previews |
22+
| Push to `main` | `main` | `preview.cambeerfestival.app` | Staging |
23+
| Version tag (e.g., `v2025.12.0`) | `release` | `cambeerfestival.app` | Production |
1524

1625
## Prerequisites
1726

@@ -92,24 +101,46 @@ You can reuse the same token by adding Pages permissions to it:
92101

93102
**Note**: Using a single token with both Workers and Pages permissions is simpler and follows the principle of consolidating CI/CD credentials for the same application.
94103

95-
### 4. Configure Custom Domain
104+
### 4. Configure Custom Domains
105+
106+
You need to set up **two custom domains** pointing to different Cloudflare Pages branches:
107+
108+
#### 4a. Production Domain (cambeerfestival.app)
96109

97110
1. In Cloudflare Dashboard, go to **Workers & Pages****Pages**
98111
2. Select your `cambeerfestival` project
99112
3. Go to **Custom domains** tab
100113
4. Click **Set up a custom domain**
101114
5. Enter: `cambeerfestival.app`
102-
6. Click **Continue**
103-
7. Cloudflare will automatically configure the DNS records
104-
8. Optionally add `www.cambeerfestival.app` as well
115+
6. **Important**: Select **Branch**: `release` (not `main`)
116+
7. Click **Continue**
117+
8. Cloudflare will automatically configure the DNS records
118+
119+
#### 4b. Preview/Staging Domain (preview.cambeerfestival.app)
120+
121+
1. In the same **Custom domains** tab
122+
2. Click **Set up a custom domain** again
123+
3. Enter: `preview.cambeerfestival.app`
124+
4. **Important**: Select **Branch**: `main`
125+
5. Click **Continue**
126+
6. Cloudflare will automatically configure the DNS records
127+
128+
#### 4c. Optional: WWW Redirect
129+
130+
If you want `www.cambeerfestival.app` to redirect to the apex domain:
131+
1. Add `www.cambeerfestival.app` as a custom domain
132+
2. Select **Branch**: `release`
105133

106134
**DNS Records Created** (automatic):
107-
- `CNAME cambeerfestival.app``cambeerfestival.pages.dev`
108-
- `CNAME www.cambeerfestival.app``cambeerfestival.pages.dev` (if www added)
135+
- `CNAME cambeerfestival.app``cambeerfestival.pages.dev` (points to `release` branch)
136+
- `CNAME preview.cambeerfestival.app``cambeerfestival.pages.dev` (points to `main` branch)
137+
- `CNAME www.cambeerfestival.app``cambeerfestival.pages.dev` (optional, points to `release` branch)
109138

110139
### 5. Update Cloudflare Worker
111140

112-
The Cloudflare Worker for API proxy has already been updated to allow `https://cambeerfestival.app` in CORS origins.
141+
The Cloudflare Worker for API proxy has already been updated to allow both custom domains in CORS origins:
142+
- `https://cambeerfestival.app` (production)
143+
- `https://preview.cambeerfestival.app` (staging)
113144

114145
When you deploy worker changes:
115146

@@ -407,13 +438,14 @@ Both should remain in free tier unless app sees very high traffic.
407438
- [ ] Cloudflare Pages project `cambeerfestival` created
408439
- [ ] Cloudflare Account ID obtained
409440
- [ ] Cloudflare API Token updated with **both** Workers Scripts + Pages permissions
410-
- [ ] Custom domain `cambeerfestival.app` configured in Cloudflare Pages
441+
- [ ] Custom domain `cambeerfestival.app` configured → points to `release` branch
442+
- [ ] Custom domain `preview.cambeerfestival.app` configured → points to `main` branch
411443
- [ ] DNS records configured (automatic via Cloudflare)
412444
- [ ] GitHub Secret `CLOUDFLARE_API_TOKEN` verified (should work for both Workers and Pages)
413445
- [ ] GitHub Secret `CLOUDFLARE_ACCOUNT_ID` added
414446
- [ ] GitHub Secret `GOOGLE_SERVICES_JSON` verified
415447
- [ ] Workflow files committed (`.github/workflows/release-web.yml` and `build-deploy.yml`)
416-
- [ ] Cloudflare Worker updated with `cambeerfestival.app` CORS origin and wildcard for Pages previews
417-
- [ ] Push to `main` triggers successful deployment to staging
448+
- [ ] Cloudflare Worker updated with both custom domains in CORS origins
449+
- [ ] Push to `main` triggers successful deployment to `https://preview.cambeerfestival.app`
418450
- [ ] Create tag triggers production deployment to `https://cambeerfestival.app`
419451
- [ ] API calls work without CORS errors on all environments

0 commit comments

Comments
 (0)