| .. | ||
| api-worker | ||
| r2-signed-urls | ||
| deploy.sh | ||
| DEPLOYMENT.md | ||
| README.md | ||
Cloudflare Workers for Rocky Mountain Vending
This directory contains Cloudflare Workers for handling API endpoints and serving content from R2 buckets.
Account Information
- Account ID:
bd6f76304a840ba11b75f9ced84264f4 - Temp Subdomain:
matt-bd6.workers.dev
Workers
API Worker (api-worker)
Main worker that handles all API endpoints:
/api/manuals/*- Serve PDF manuals from R2 bucket/api/thumbnails/*- Serve thumbnail images from R2 bucket/api/sitemap-submit- Submit sitemap to Google Search Console/api/request-indexing- Request URL indexing in Google Search Console/health- Health check endpoint
Prerequisites
-
R2 Buckets: Create the following buckets in Cloudflare Dashboard:
vending-vm-manuals- For PDF manualsvending-vm-thumbnails- For thumbnail images
-
Wrangler CLI: Install Wrangler if not already installed:
npm install -g wrangler -
Authentication: Login to Cloudflare:
wrangler login
Setup
1. Create R2 Buckets
# Create manuals bucket
wrangler r2 bucket create vending-vm-manuals
# Create thumbnails bucket
wrangler r2 bucket create vending-vm-thumbnails
2. Configure R2 Bucket Access
In Cloudflare Dashboard:
- Go to R2 → Select bucket → Settings
- Enable public access if you want public URLs
- Configure CORS if accessing from different domains
3. Set Environment Variables (Optional)
For Google Search Console integration:
# Set Google service account email
wrangler secret put GOOGLE_SERVICE_ACCOUNT_EMAIL
# Set Google private key (paste the full key including \n)
wrangler secret put GOOGLE_PRIVATE_KEY
# Set site URL
wrangler secret put GOOGLE_SITE_URL
# Enter: https://rockymountainvending.com
# Set main site URL
wrangler secret put SITE_URL
# Enter: https://rockymountainvending.com
4. Deploy the Worker
From the code directory:
# Deploy to production
wrangler deploy
# Deploy to development environment
wrangler deploy --env development
The worker will be available at:
- Production:
https://rocky-mountain-vending-api.matt-bd6.workers.dev - Development:
https://rocky-mountain-vending-api-dev.matt-bd6.workers.dev
Usage
Serve Manuals
GET https://rocky-mountain-vending-api.matt-bd6.workers.dev/api/manuals/Crane/manual.pdf
Serve Thumbnails
GET https://rocky-mountain-vending-api.matt-bd6.workers.dev/api/thumbnails/Crane/manual.jpg
Submit Sitemap
curl -X POST https://rocky-mountain-vending-api.matt-bd6.workers.dev/api/sitemap-submit \
-H "Content-Type: application/json" \
-d '{"sitemapUrl": "https://rockymountainvending.com/sitemap.xml"}'
Request Indexing
curl -X POST https://rocky-mountain-vending-api.matt-bd6.workers.dev/api/request-indexing \
-H "Content-Type: application/json" \
-d '{"url": "https://rockymountainvending.com/manuals"}'
Health Check
GET https://rocky-mountain-vending-api.matt-bd6.workers.dev/health
Custom Domain Setup
To use a custom domain instead of the workers.dev subdomain:
- Go to Cloudflare Dashboard → Workers & Pages
- Select your worker
- Go to Settings → Triggers
- Add a custom domain or route
Example routes:
api.rockymountainvending.com/*- Route all API requestsrockymountainvending.com/api/*- Route API requests from main domain
R2 Bucket Structure
Manuals Bucket (vending-vm-manuals)
Store PDF files with manufacturer folders:
Crane/
manual1.pdf
manual2.pdf
Royal Vendors/
manual1.pdf
...
Thumbnails Bucket (vending-vm-thumbnails)
Store thumbnail images matching manual structure:
Crane/
manual1.jpg
manual2.jpg
Royal Vendors/
manual1.jpg
...
Development
Local Development
# Start local development server
wrangler dev
# Start with specific environment
wrangler dev --env development
Testing
# Test health endpoint
curl https://rocky-mountain-vending-api.matt-bd6.workers.dev/health
# Test manual endpoint (requires file in R2)
curl https://rocky-mountain-vending-api.matt-bd6.workers.dev/api/manuals/Crane/manual.pdf
Troubleshooting
Worker Not Found
- Verify account ID in
wrangler.tomlmatches your Cloudflare account - Check that you're logged in:
wrangler whoami
R2 Bucket Not Found
- Verify bucket names match in
wrangler.toml - Check buckets exist:
wrangler r2 bucket list - Ensure buckets are in the same account
CORS Errors
- Add CORS headers in worker response
- Configure CORS in R2 bucket settings if using public URLs
- Check allowed origins in worker code
Google Search Console API
The Google Search Console integration requires additional setup:
- Enable Google Search Console API in Google Cloud Console
- Create service account and download credentials
- Grant service account access in Google Search Console
- Install
googleapislibrary (may require bundling for Workers)
See docs/operations/SEO_SETUP.md for detailed instructions.
Monitoring
View worker logs and metrics in Cloudflare Dashboard:
- Workers & Pages → Your Worker → Logs
- Workers & Pages → Your Worker → Metrics
Cost Considerations
- Workers: Free tier includes 100,000 requests/day
- R2: Pay-as-you-go storage and egress
- Custom Domains: Included with Workers
Monitor usage in Cloudflare Dashboard → Billing.