Skip to content

Commit 6eaec27

Browse files
Merge pull request #106 from richardthe3rd/copilot/update-routing-method-to-path
Enable path-based URL routing for web deployments
2 parents fa66f29 + e3c7e18 commit 6eaec27

9 files changed

Lines changed: 89 additions & 72 deletions

File tree

.github/workflows/build-deploy.yml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99

1010
permissions:
1111
contents: read
12-
pages: write
1312
id-token: write
1413
pull-requests: write
1514
deployments: write
@@ -252,32 +251,6 @@ jobs:
252251
path: build/app/outputs/flutter-apk/app-debug.apk
253252
if-no-files-found: error
254253

255-
deploy-web:
256-
needs: [build-web, test-e2e-web]
257-
runs-on: ubuntu-latest
258-
if: github.ref == 'refs/heads/main'
259-
environment:
260-
name: github-pages
261-
url: ${{ steps.deployment.outputs.page_url }}
262-
steps:
263-
- name: Download build artifact
264-
uses: actions/download-artifact@v4
265-
with:
266-
name: web-build
267-
path: build/web
268-
269-
- name: Setup Pages
270-
uses: actions/configure-pages@v4
271-
272-
- name: Upload to GitHub Pages
273-
uses: actions/upload-pages-artifact@v3
274-
with:
275-
path: build/web
276-
277-
- name: Deploy to GitHub Pages
278-
id: deployment
279-
uses: actions/deploy-pages@v4
280-
281254
deploy-web-preview:
282255
needs: [changes, build-web, test-e2e-web]
283256
runs-on: ubuntu-latest

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ cd scripts && npm install && node validate-festivals.js
248248

249249
The project uses GitHub Actions for:
250250
1. **Build**: Analyze code, run tests, build web
251-
2. **Deploy**: Deploy to GitHub Pages (main branch only)
251+
2. **Deploy**: Deploy to Cloudflare Pages (main branch and PRs)
252252
3. **Worker**: Deploy Cloudflare Worker when changed
253253

254254
## Do Not Modify

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ API documentation and JSON schemas are available in the [docs/api](docs/api/) di
137137
- [Beer List Schema](docs/api/beer-list-schema.json) - JSON Schema for beverage data
138138
- [Festival Registry Schema](docs/api/festival-registry-schema.json) - JSON Schema for festival configuration
139139

140+
## Architecture & Documentation
141+
142+
Technical documentation is available in the [docs](docs/) directory:
143+
144+
- [URL Routing](docs/URL_ROUTING.md) - Path-based routing implementation and configuration
145+
- [Cloudflare Pages Setup](docs/CLOUDFLARE_PAGES_SETUP.md) - Deployment configuration
146+
- [CI/CD](docs/CICD.md) - Complete CI/CD workflow documentation
147+
- [Testing](docs/TESTING_FLUTTER_WEB.md) - Testing Flutter web applications
148+
140149
## Deployment
141150

142151
The app is deployed to multiple environments:
@@ -150,18 +159,14 @@ The app is deployed to multiple environments:
150159
- Deployed automatically on push to `main`
151160
- Uses Cloudflare Pages project `cambeerfestival-staging`, branch `main`
152161
- Workflow: `.github/workflows/build-deploy.yml` (deploy-web-preview job)
153-
- **Development** (GitHub Pages): [richardthe3rd.github.io/cambridge-beer-festival-app](https://richardthe3rd.github.io/cambridge-beer-festival-app/)
154-
- Alternative development environment
155-
- Deployed automatically on push to `main`
156-
- Workflow: `.github/workflows/build-deploy.yml` (deploy-web job)
157162
- **PR Previews** (Cloudflare Pages): Unique URL per pull request
158163
- Each PR gets its own preview environment (e.g., `<branch>.cambeerfestival-staging.pages.dev`)
159164
- Preview URL posted as comment on the PR
160165
- Workflow: `.github/workflows/build-deploy.yml` (deploy-web-preview job)
161166

162167
### Deployment Strategy
163168

164-
1. **Development changes**: Push to `main` → Staging (Cloudflare) + GitHub Pages updated
169+
1. **Development changes**: Push to `main` → Staging (Cloudflare Pages)
165170
2. **PR reviews**: Open PR → Unique Cloudflare Pages preview created
166171
3. **Production releases**: Create tag (e.g., `v2025.12.0`) → Production deployment to cambeerfestival.app
167172

cloudflare-worker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Cloudflare Worker - CORS Proxy
22

3-
This Cloudflare Worker proxies requests to `data.cambridgebeerfestival.com` and adds CORS headers, allowing the Flutter web app hosted on GitHub Pages to access the API data.
3+
This Cloudflare Worker proxies requests to `data.cambridgebeerfestival.com` and adds CORS headers, allowing the Flutter web app to access the API data.
44

55
## How It Works
66

docs/CICD.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ on:
3434
workflow_dispatch:
3535
```
3636
37-
- **Push to `main`**: Full build, test, deploy to GitHub Pages + Cloudflare Pages staging
37+
- **Push to `main`**: Full build, test, deploy to Cloudflare Pages staging
3838
- **Pull Requests**: Build, test, deploy preview to Cloudflare Pages
3939
- **Push to `copilot/**`**: CI builds for Copilot branches
4040
- **Manual**: Via workflow_dispatch in GitHub Actions UI
@@ -108,22 +108,7 @@ Builds Android APK and App Bundle.
108108
- Gradle dependency caching reduces build time by 2-5 minutes on cache hits
109109
- Gradle build cache enabled (see gradle.properties)
110110

111-
#### E. `deploy-web`
112-
113-
Deploys to **GitHub Pages** (development environment).
114-
115-
**Runs when**: Push to `main` branch
116-
117-
**Environment**: `github-pages`
118-
**URL**: `https://richardthe3rd.github.io/cambridge-beer-festival-app/`
119-
120-
**Steps:**
121-
1. Download `web-build` artifact
122-
2. Setup GitHub Pages
123-
3. Upload to Pages
124-
4. Deploy
125-
126-
#### F. `deploy-web-preview`
111+
#### E. `deploy-web-preview`
127112

128113
Deploys to **Cloudflare Pages** (staging and PR previews).
129114

@@ -382,8 +367,7 @@ See [GITHUB_SECRETS.md](GITHUB_SECRETS.md) for setup instructions.
382367

383368
4. **Merge to `main`**
384369
- Triggers deployment to:
385-
- GitHub Pages (development)
386-
- Cloudflare Pages staging (`main.cambeerfestival.pages.dev`)
370+
- Cloudflare Pages staging (`staging.cambeerfestival.app`)
387371
- If worker/festivals.json changed:
388372
- Deploys updated worker
389373

docs/CLOUDFLARE_PAGES_SETUP.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ The app uses **two separate Cloudflare Pages projects** for clean separation bet
3030
| Version tag | `cambeerfestival` | `release` | `cambeerfestival.app` | Production |
3131
| Push to `main` | `cambeerfestival-staging` | `main` | `staging.cambeerfestival.app` | Staging |
3232
| Pull Request | `cambeerfestival-staging` | `<branch>` | `<branch>.cambeerfestival-staging.pages.dev` | PR previews |
33-
| Push to `main` | GitHub Pages | N/A | `richardthe3rd.github.io/...` | Development |
3433

3534
## Prerequisites
3635

@@ -319,18 +318,6 @@ This workflow handles all non-production deployments and includes multiple jobs:
319318
- Share preview URLs with team members for review
320319
- No conflicts with staging environment
321320

322-
#### C. Development Deployment (GitHub Pages)
323-
324-
**Trigger**: Push to `main` branch
325-
326-
**Job**: `deploy-web`
327-
328-
**Automatic process**:
329-
330-
1. Push or merge to `main`
331-
2. Deploys to `richardthe3rd.github.io/cambridge-beer-festival-app/`
332-
3. Serves as alternative development/testing environment
333-
334321
## Verification
335322

336323
After deployment, verify:
@@ -399,9 +386,7 @@ If you see CORS errors in browser console:
399386

400387
1. Make changes to code
401388
2. Commit and push to `main` branch
402-
3. GitHub Actions automatically deploys to both:
403-
- GitHub Pages (staging)
404-
- Cloudflare Pages (production)
389+
3. GitHub Actions automatically deploys to Cloudflare Pages staging
405390

406391
### Updating Festivals Data
407392

docs/PLAY_STORE_METADATA.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ adb pull /sdcard/screenshot.png
140140

141141
You **must** provide a privacy policy URL. Host it on:
142142
- Your website
143-
- GitHub Pages
143+
- Cloudflare Pages
144144
- Google Docs (make it public)
145145

146146
**Privacy Policy Template** (copy and customize):
@@ -209,8 +209,8 @@ For questions about this privacy policy, contact:
209209

210210
**Where to host:**
211211
- Create `docs/privacy-policy.md` in your repo
212-
- Enable GitHub Pages on the repo
213-
- Use URL: `https://yourusername.github.io/cambridge-beer-festival-app/privacy-policy.html`
212+
- Deploy to Cloudflare Pages
213+
- Use URL: `https://cambeerfestival.app/privacy-policy.html` or `https://staging.cambeerfestival.app/privacy-policy.html`
214214

215215
## 🎯 Content Rating
216216

docs/URL_ROUTING.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# URL Routing Strategy
2+
3+
This document explains how URL routing works in the Cambridge Beer Festival app.
4+
5+
## Overview
6+
7+
The app uses **path-based routing** (e.g., `/favorites`, `/drink/123`) instead of **hash-based routing** (e.g., `/#/favorites`, `/#/drink/123`).
8+
9+
## Implementation
10+
11+
### Flutter Side
12+
13+
The app uses [go_router](https://pub.dev/packages/go_router) version 14.6.2 (or later) for routing. Starting from go_router 7.0.0, path-based URL strategy is the default on web platforms, so no additional configuration is needed in the Flutter code.
14+
15+
### Web Server Configuration
16+
17+
For path-based routing to work correctly on deployed web apps, the web server must be configured to serve `index.html` for all routes (SPA fallback). This is because when a user navigates directly to a route like `/favorites`, the web server needs to serve the main `index.html` file, which then loads the Flutter app that handles the routing internally.
18+
19+
#### Cloudflare Pages (Production & Staging)
20+
21+
**File**: `web/_redirects`
22+
23+
```
24+
/* /index.html 200
25+
```
26+
27+
This tells Cloudflare Pages to serve `index.html` for all routes with a 200 status code. Cloudflare Pages natively supports the `_redirects` file format.
28+
29+
#### Local Development with http-server
30+
31+
For local testing, the project uses `http-server` with the `--proxy` flag to handle SPA routing:
32+
33+
```bash
34+
npx http-server build/web -p 8080 -c-1 -a 127.0.0.1 --proxy http://127.0.0.1:8080?
35+
```
36+
37+
The `--proxy` flag tells http-server to fall back to serving `index.html` for routes that don't exist as physical files, enabling proper SPA behavior during local development and E2E testing.
38+
39+
## Routes
40+
41+
The app supports the following routes:
42+
43+
- `/` - Home screen (drinks list)
44+
- `/favorites` - Favorites screen
45+
- `/about` - About screen
46+
- `/festival-info` - Festival information screen
47+
- `/drink/:id` - Drink detail screen (parameterized)
48+
- `/brewery/:id` - Brewery screen (parameterized)
49+
- `/style/:name` - Style screen (parameterized, URL-encoded)
50+
51+
## Testing
52+
53+
E2E tests in `test-e2e/routing.spec.ts` verify:
54+
- Path-based URLs work correctly
55+
- Deep linking to specific routes works
56+
- Browser back/forward buttons work
57+
- Page refresh preserves the current route
58+
59+
## Benefits of Path-Based Routing
60+
61+
1. **Better SEO**: Search engines can properly index individual pages
62+
2. **Clean URLs**: URLs look cleaner and more professional
63+
3. **Shareable Links**: Users can share direct links to specific content
64+
4. **Standard Web Behavior**: Works like traditional websites
65+
5. **Better Analytics**: Analytics tools can track page views more accurately
66+
67+
## Migration Notes
68+
69+
If you were previously using the app with hash-based routing, existing bookmarks with hash URLs (e.g., `/#/favorites`) will continue to work because go_router handles the migration automatically.

web/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* /index.html 200

0 commit comments

Comments
 (0)