A lightweight proxy server for bypassing CORS restrictions when streaming M3U8 content.
- Proxy M3U8 playlist files with rewritten URLs
- Proxy TS segment files
- Automatic URL resolution and rewriting
- CORS headers support
- Custom headers support
- Domain-specific header templates for anti-hotlinking bypass
- TS segment caching with cache control headers
- Dynamic header assignment based on request domains
- Error handling
- Clone the repository
- Install dependencies:
npm install
Create a .env
file with the following variables:
HOST=localhost
PORT=3000
PUBLIC_URL=http://localhost:3000
ALLOWED_ORIGINS=https://example.com,https://another-domain.com
Start the server:
npm start
For development with auto-restart:
npm run dev
GET /proxy?url={m3u8_url}&headers={optional_headers}
Parameters:
url
(required): The URL of the M3U8 playlistheaders
(optional): JSON-encoded headers to send with the request
GET /ts-proxy?url={segment_url}&headers={optional_headers}
Parameters:
url
(required): The URL of the TS segmentheaders
(optional): JSON-encoded headers to send with the request
To proxy an M3U8 playlist:
http://localhost:3000/proxy?url=https://example.com/playlist.m3u8
To proxy an M3U8 playlist with custom headers:
http://localhost:3000/proxy?url=https://example.com/playlist.m3u8&headers={"Authorization":"Bearer token"}
The proxy automatically applies domain-specific headers to bypass anti-hotlinking protections. These headers are defined in domainTemplates.js
and include:
- User-Agent strings specific to each domain
- Accept headers that match typical browser requests
- Origin and Referer headers that match the domain
- Other domain-specific headers required for access
The system automatically detects the domain from the URL and applies the appropriate headers. Custom headers provided via the headers
parameter will be merged with the domain-specific headers.
TS segments are cached in memory for 5 minutes to improve performance and reduce redundant network requests. Cached responses include appropriate cache control headers for client-side caching.
Cache headers:
X-Cache: HIT
- Response was served from cacheX-Cache: MISS
- Response was fetched from the origin server
You can also run this proxy server using Docker:
-
Build the Docker image:
docker build -t m3u8-proxy .
-
Run the container:
docker run -p 3000:3000 -e HOST=0.0.0.0 -e PORT=3000 m3u8-proxy
-
Or run with custom environment variables:
docker run -p 3000:3000 -e HOST=0.0.0.0 -e PORT=3000 -e ALLOWED_ORIGINS=https://yourdomain.com m3u8-proxy
- The M3U8 proxy fetches the playlist and rewrites all URLs to point back to this proxy server
- When a player requests a segment, it goes through the TS proxy
- All requests include proper CORS headers
MIT