This Cloudflare Worker proxies requests to data.cambridgebeerfestival.com and adds CORS headers, allowing the Flutter web app to access the API data.
- The Flutter app makes requests to
https://cbf-data-proxy.<your-subdomain>.workers.dev/cbf2025/beer.json - The worker fetches data from
https://data.cambridgebeerfestival.com/cbf2025/beer.json - The worker adds CORS headers and returns the response to the app
- A Cloudflare account (free tier works)
CLOUDFLARE_API_TOKENsecret added to GitHub repository
- Go to Cloudflare Dashboard
- Navigate to My Profile → API Tokens
- Click Create Token
- Use the Edit Cloudflare Workers template, or create a custom token with:
- Account → Workers Scripts → Edit
- Zone → Workers Routes → Edit (if using custom domain)
- Copy the token and add it as
CLOUDFLARE_API_TOKENin GitHub repository secrets
If you want to deploy manually first:
cd cloudflare-worker
npm install
npx wrangler login
npx wrangler deployThe worker URL will be displayed after deployment (e.g., https://cbf-data-proxy.<account>.workers.dev).
The GitHub Actions workflow automatically deploys the worker on push to main. Ensure:
CLOUDFLARE_API_TOKENis set in repository secrets (Settings → Secrets and variables → Actions → New repository secret)
Troubleshooting: If you see "Unable to authenticate request [code: 10001]", your API token may be:
- Missing from GitHub secrets
- Expired or revoked
- Missing required permissions (needs "Workers Scripts: Edit" at minimum)
The worker provides several endpoints:
Proxies requests to data.cambridgebeerfestival.com with CORS headers:
/{festivalId}/{beverageType}.json- Get beverage data (e.g.,/cbf2025/beer.json)
Dynamic API endpoints that provide festival metadata:
/festivals.json- Returns the festivals registry with all festival metadata/{festivalId}/available_beverage_types.json- NEW! Dynamically discovers available beverage types for a festival
Example:
# Get available beverage types for CBF 2025
curl https://cbf-data-proxy.<your-subdomain>.workers.dev/cbf2025/available_beverage_types.json
# Response:
{
"festival_id": "cbf2025",
"available_beverage_types": [
"apple-juice",
"beer",
"cider",
"international-beer",
"low-no",
"mead",
"perry",
"wine"
],
"timestamp": "2025-12-02T10:30:00.000Z"
}This endpoint:
- Dynamically fetches the directory listing from the upstream API
- Parses the HTML to find all
.jsonfiles - Returns them as a sorted array
- Caches the result for 1 hour
/health- Returns{"status": "ok"}for monitoring
After deployment, test the proxy:
# Test beverage data proxy
curl https://cbf-data-proxy.<your-subdomain>.workers.dev/cbf2025/beer.json
# Test dynamic beverage types discovery
curl https://cbf-data-proxy.<your-subdomain>.workers.dev/cbf2025/available_beverage_types.json
# Test festivals registry
curl https://cbf-data-proxy.<your-subdomain>.workers.dev/festivals.jsonOnce deployed, update lib/models/festival.dart to use the proxy URL:
dataBaseUrl: 'https://data.cambeerfestival.app/cbf2025',Or configure it dynamically based on the platform (see lib/services/beer_api_service.dart).