- Issue: App showed demo data instead of real YouTube channel videos
- Root Cause: Missing
YOUTUBE_API_KEYenvironment variable in Cloudflare Worker - Solution:
- Updated
wrangler.jsoncwith proper environment binding - Added YouTube API key as a Cloudflare secret
- Worker now fetches from channel
UCrjJP_SHUeCmqpTSHJCXkdA
- Updated
- Issue: Buttons not responding, modals didn't appear, search broken
- Root Cause: DOM element IDs mismatch between HTML and JavaScript
- Solution:
- Rebuilt
index.htmlwith correct ID mapping - Fixed all
app.jselement selectors - All interactive features now functional
- Rebuilt
- Issue: Docker build failing, compose configuration broken
- Root Cause: Incorrect Dockerfile base image, broken compose services
- Solution:
- Created proper multi-stage Nginx Dockerfile
- Fixed docker-compose.yml configuration
- Updated .dockerignore to include dist folder
- Docker & Docker Compose
- Wrangler CLI (
npm install -g @cloudflare/wrangler) - YouTube API key from Google Cloud Console
- Cloudflare account with Workers enabled
- Go to Google Cloud Console
- Create a new project or select existing one
- Search for "YouTube Data API v3" and enable it
- Go to "Credentials" → "Create Credentials" → "API Key"
- Copy the generated API key
# Add your YouTube API key to Cloudflare
wrangler secret put YOUTUBE_API_KEY --env production
# Paste your API key when prompted
# Deploy the worker
wrangler deploy --env production
# Verify deployment
curl https://yt-studio-production.ruhdevopsytstudio.workers.dev/api/channel# Build Docker image
docker build -t yt-studio-web:latest .
# Start the application
docker compose up -d
# View logs
docker logs -f yt-studio-web
# Access at http://localhost:8080Visit http://localhost:8080 and check:
- Videos load from your YouTube channel
- Click on a video to play it
- Search functionality works
- Filter chips (categories) work
- Bookmark button saves videos
- Share buttons work
- Theme toggle works
- Watch Later panel opens
YT-Studio/
├── index.html # Main page with all UI elements
├── Dockerfile # Nginx container for frontend
├── docker-compose.yml # Container orchestration
├── wrangler.jsonc # Cloudflare Worker config
├── .env.example # Environment template
├── .dockerignore # Docker build exclusions
│
├── js/
│ └── app.js # Main app logic (30KB minified)
│
├── css/
│ └── style.css # Styling
│
├── dist/ # Built/ready-to-deploy files
│ ├── index.html
│ ├── js/
│ ├── css/
│ └── public/
│
├── src/
│ └── youtube-worker.ts # Cloudflare Worker source
│
├── yt-proxy/ # API proxy configuration
│
└── DEPLOYMENT_FIXES.md # Complete fix documentation
┌─────────────────────────────────────┐
│ Browser (User) │
│ http://localhost:8080 │
└──────────────┬──────────────────────┘
│
↓
┌─────────────────────────────────────┐
│ Nginx Container (Frontend) │
│ - SPA routing (index.html) │
│ - Static files (CSS, JS) │
│ - API proxy to Worker │
└──────────────┬──────────────────────┘
│ /api/* requests
↓
┌─────────────────────────────────────┐
│ Cloudflare Workers (API) │
│ - YouTube API v3 integration │
│ - Channel: UCrjJP_SHUeCmqpTSHJCXkdA │
│ - Endpoints: │
│ - /api/channel (stats) │
│ - /api/videos (list) │
│ - /api/search (search) │
└──────────────┬──────────────────────┘
│
↓
┌─────────────────────────────────────┐
│ YouTube Data API v3 │
│ - Fetches channel metadata │
│ - Lists videos │
│ - Searches videos │
└─────────────────────────────────────┘
- Click any episode to watch in modal player
- YouTube player with quality controls
- Picture-in-picture (PiP) support
- Resume from last watched position
- Real-time search with keyboard focus (press
/) - Filter by categories (History, Quranic Studies, Prophecy, Discussion)
- Search suggestions dropdown
- Clear search button
- Click bookmark icon to save episodes
- Dedicated Watch Later panel
- Saved episodes persist in localStorage
- Badge shows count of saved items
- Total episodes loaded
- Saved episodes count
- Watch progress tracking
- Category distribution chart
- Resume watching list
- Dark/light theme toggle
- Mobile responsive design
- Keyboard shortcuts:
/- Focus searchEscape- Close all modalsj/k- Previous/next video (while playing)t- Toggle theme
- Smooth animations and transitions
- Accessibility (ARIA labels, semantic HTML)
All endpoints return JSON and support CORS.
GET / or /healthReturns worker status and available endpoints.
GET /api/channelReturns channel statistics, subscribers, view count, total videos.
GET /api/videos?maxResults=12&pageToken=<token>Returns channel's uploaded videos with:
- Video ID
- Title
- Description
- Thumbnail URL
- Published date
- Auto-detected category
GET /api/search?q=<query>Searches channel videos for matching titles/descriptions.
Create .env file:
YOUTUBE_API_KEY=your_api_key_here
YOUTUBE_CHANNEL_ID=UCrjJP_SHUeCmqpTSHJCXkdA
NODE_ENV=production
LOG_LEVEL=infoFor Cloudflare Workers:
wrangler secret put YOUTUBE_API_KEY --env production- Verify Worker deployment:
wrangler status
- Check API key is set:
wrangler secret list --env production
- Test Worker endpoint:
curl https://yt-studio-production.ruhdevopsytstudio.workers.dev/api/videos
- Check browser console for CORS errors
- Open DevTools (F12) → Console tab
- Look for JavaScript errors
- Clear localStorage:
localStorage.clear() - Refresh page
# Check logs
docker logs yt-studio-web -f
# Rebuild
docker compose down --remove-orphans
docker build --no-cache -t yt-studio-web:latest .
docker compose up# Re-authenticate
wrangler logout
wrangler login
# Deploy with verbose output
wrangler deploy --env production --verbose- Videos cached for 24 hours in localStorage
- Lazy loading for images
- Optimized CSS/JS (minified)
- Service worker ready (register in
app.js)
- Respects YouTube API rate limits (100M units/day)
- Caches responses for 1 hour
- Returns demo data if API fails
- Minimal response size (~2KB per request)
- Multi-stage build (only 20MB runtime)
- Alpine Linux (lightweight)
- Gzip compression enabled
- Browser caching for assets (1 year)
# Build
pnpm run build
# Deploy dist/ folder
# Set environment variables in dashboard# Build image
docker build -t your-registry/yt-studio:latest .
# Push to registry
docker push your-registry/yt-studio:latest
# Update deployment with new image# Build and deploy
wrangler deploy --env production- YouTube API key obtained from Google Cloud
-
YOUTUBE_API_KEYset in Cloudflare Workers - Worker deployed:
wrangler deploy --env production - Docker image built:
docker build -t yt-studio-web:latest . - Container runs:
docker compose up -d - Videos load from real channel (not demo)
- All buttons functional (play, bookmark, share, theme)
- Search works with real data
- Mobile responsive on phone
- No console errors in DevTools
- Lighthouse score > 80
- YouTube API Docs: https://developers.google.com/youtube/v3
- Cloudflare Workers: https://developers.cloudflare.com/workers/
- Docker Docs: https://docs.docker.com/
- Your Channel: https://www.youtube.com/@Ruh-Al-Tarikh
Status: ✅ Fully Functional
Last Updated: 2024-05-07
Channel: Ruh Al Tarikh (UCrjJP_SHUeCmqpTSHJCXkdA)