How ctzzg/libretv works
Project type and purpose
• LibreTV is a full-stack, serverless‐style web application that delivers a lightweight, password‐protected video search and playback platform.
• It combines a static front end (HTML/CSS/JS, PWA, service worker) with backend proxy functionality implemented as serverless functions (Netlify, Vercel, Cloudflare) and a standalone Node.js server for local/docker development.
File structure
• Top‐level assets:
• index.html, player.html, watch.html, about.html, privacy.html – static entry points
• css/, js/ – frontend resources (styles, UI logic, video player integration)
• service-worker.js, manifest.json – PWA support
• image/ – branding assets
• Backend / serverless:
• api/proxy/[...path].mjs & functions/proxy/[[path]].js & netlify/functions/proxy.mjs – unified API proxy endpoints
• server.mjs & middleware.js – Express‐style server for local and Docker use
• proxy.lua & nginx.conf – optional Nginx-based proxy for Docker/Nginx deployments
• Deployment/config:
• Dockerfile, docker-compose.yml, docker-entrypoint.sh – containerized deployment
• netlify.toml, vercel.json – serverless hosting config
• .github/workflows/*.yml – CI/CD for versioning, Docker builds, syncing
• .env.example – environment variable template (PASSWORD, PORT)
README for additional insights
• Describes architecture as “static front end + serverless proxy” supporting Apple CMS V10 API
• Emphasizes password protection via PASSWORD env var
• Lists deployment targets: Cloudflare Pages, Vercel, Netlify, Docker
a. Main components:
1. Client Browser
• Loads static assets from CDN/hosting (HTML, CSS, JS)
• Registers Service Worker / PWA
• Renders UI, interacts via JS (api.js, player.js, watch.js)
2. Static Asset Hosting
• Vercel/Netlify/Cloudflare Pages or Docker/nginx static server
3. Proxy Backend
• Serverless Functions (api/proxy, functions/proxy, netlify/functions)
• Local Node.js server (server.mjs + middleware.js)
• Optional Nginx + Lua proxy
4. External Video Content APIs
• Third‐party “Apple CMS” V10 endpoints for search & detail
• HLS video streaming URLs
5. Data Stores / LocalStorage
• Browser localStorage for settings, version checks, password
b. Relationships and interactions:
• Browser → Static Host: GET HTML/CSS/JS/manifest
• Browser → Service Worker (intercepts, caches)
• JS in Browser → Proxy Backend: AJAX calls to /api/proxy/...
• Proxy Backend → External APIs/HLS Sources: fetch & rewrite
• Proxy Backend → Browser: proxied JSON, M3U8 playlists, media segments
• Browser → LocalStorage: read/write settings & PASSWORD
c. Architectural patterns & principles:
• “Jamstack” style: prebuilt static + serverless functions
• PWA + Service Worker caching for offline/resume
• API Gateway pattern: single proxy entrypoint abstracts CORS & API versions
• Deployment‐agnostic: adapters for Netlify/Vercel/Cloudflare Functions or Docker/Express
d. Key technologies:
• Frontend: HTML5, CSS3 (Tailwind in build pipeline), ES6+ JS, DPlayer, HLS.js
• Backend: Node.js (server.mjs), Express‐like middleware, serverless function runtimes
• Proxy: Lua (optional), Netlify/Vercel/Cloudflare Function APIs
• Deployment: Docker, docker-compose, GitHub Actions
Detail
• Serverless endpoint path (/api/proxy/[...path], /proxy.mjs)
• Branching for Netlify vs. Vercel vs. Cloudflare vs. Docker flows
• Password‐check middleware in your proxy block
• HLS stream rewriting logic, Service Worker cache strategy, and PWA manifest