Overview
OfflineTube uses environment variables to configure the connection between the frontend and backend API. The primary configuration variable isNEXT_PUBLIC_API_URL, which determines how the frontend communicates with the FastAPI backend.
NEXT_PUBLIC_API_URL
The base URL for the OfflineTube FastAPI backend. When set, the frontend will use this URL for all API requests.If not set, the frontend automatically resolves the API URL based on the current hostname and protocol.
Auto-Resolution Logic
The frontend uses the following resolution strategy (fromsrc/app/page.tsx:19-30):
- Check environment variable: If
NEXT_PUBLIC_API_URLis set and not empty, use that value - Auto-detect from hostname: If running in browser, construct URL as
{protocol}://{hostname}:8001- Uses
httpsif current page is HTTPS, otherwisehttp - Uses the current hostname (e.g.,
192.168.1.100orlocalhost)
- Uses
- Fallback: Default to
http://localhost:8001
Configuration Examples
Local Development
For local development, no environment variable is needed. The auto-detection works automatically:http://localhost:3000 will automatically connect to http://localhost:8001.
Explicit Local Configuration
To explicitly set the API URL, create a.env.local file:
LAN Access
When accessing from other devices on your local network, no configuration is needed. The frontend automatically detects the hostname:Custom Backend Location
If your backend is on a different host or port:Production Deployment
For production with reverse proxy:Environment Variable Best Practices
Variables prefixed with
NEXT_PUBLIC_ are embedded in the frontend bundle at build time and exposed to the browser.Development
Use.env.local for local development (this file is gitignored):
Production Build
Set environment variables before building:.env.production file:
Verifying Configuration
The resolved API URL is displayed in the Settings panel:- Open OfflineTube
- Navigate to Configuración (Settings) tab
- Check the API URL field under Conexión
- The displayed URL shows the active backend connection
Troubleshooting
Common Issues
Frontend can’t connect to backend Check the browser console for the API URL being used:0.0.0.0:8001 (not 127.0.0.1:8001). The default configuration in mini-services/offlinetube-api/main.py:682 already uses 0.0.0.0.