mirror of
https://gitlab.com/vyla-entertainment/documentation.git
synced 2026-11-14 22:47:26 -05:00
fixed syntax issues
This commit is contained in:
@@ -1,41 +1,34 @@
|
||||
# Self-Hosting Stream API
|
||||
|
||||
<p class="page-description">Complete production self-hosting guide for Stream API: Docker, Node.js systemd, PM2, and Nginx reverse proxy configuration with SSE streaming support.</p>
|
||||
<p class="page-description">Production self-hosting guide for Stream API using Docker, systemd, and Nginx with SSE streaming support.</p>
|
||||
|
||||
## Overview
|
||||
|
||||
Stream API is designed to be completely self-hostable on any Linux virtual private server (VPS), home server, or Docker container environment. Running your own instance gives you private access, eliminates shared IP rate limits, and allows you to tune worker concurrency to your hardware.
|
||||
Stream API can be self-hosted on any Linux VPS, home server, or container environment. Self-hosting eliminates shared IP rate limits and allows custom worker tuning.
|
||||
|
||||
---
|
||||
|
||||
## Environment Variables
|
||||
## Configuration
|
||||
|
||||
Configure your environment variables via a `.env` file in the project root:
|
||||
Configure environment variables via a `.env` file in the project root:
|
||||
|
||||
| Variable | Required | Default | Description |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| `PORT` | Optional | `7860` | HTTP port on which the server binds. |
|
||||
| `TMDB_API_KEY` | **Recommended** | `""` | The Movie Database v3 API key. Required for scrapers that resolve metadata via IMDb ID or episode titles. |
|
||||
| `WORKER_COUNT` | Optional | `os.cpus().length` | Number of worker processes to fork in cluster mode. |
|
||||
| `ENABLE_DEBUG_ROUTE` | Optional | `false` | Enables deep diagnostic traces at `/debug/:source`. Keep `false` in production. |
|
||||
| `GA_MEASUREMENT_ID` | Optional | `""` | Google Analytics 4 Measurement ID for private usage telemetry. |
|
||||
| `GA_API_SECRET` | Optional | `""` | Google Analytics 4 Measurement Protocol API Secret. |
|
||||
| `FALLBACK_BASE` | Optional | `""` | Secondary Stream API instance URL used for failover redirects. |
|
||||
| `IS_HF` | Optional | `false` | Enables HuggingFace Spaces compatibility constraints. |
|
||||
- `PORT` *(number, optional)* — Bind port. Default: `7860`.
|
||||
- `TMDB_API_KEY` *(string, recommended)* — TMDB v3 API key for metadata lookups.
|
||||
- `WORKER_COUNT` *(number, optional)* — Number of cluster workers. Default: available CPU count.
|
||||
- `ENABLE_DEBUG_ROUTE` *(boolean, optional)* — Enables `/debug/:source`. Keep `false` in production.
|
||||
- `FALLBACK_BASE` *(string, optional)* — Secondary Stream API URL for failover redirects.
|
||||
- `IS_HF` *(boolean, optional)* — Enables HuggingFace Spaces compatibility.
|
||||
|
||||
---
|
||||
|
||||
## Deployment Option 1: Docker (Recommended)
|
||||
|
||||
### 1. Dockerfile
|
||||
Create a `Dockerfile` in the project directory:
|
||||
## Deployment Option 1: Docker
|
||||
|
||||
### Dockerfile
|
||||
```dockerfile
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install native dependencies required for TLS and encryption
|
||||
RUN apk add --no-cache python3 make g++
|
||||
|
||||
COPY package*.json ./
|
||||
@@ -49,9 +42,7 @@ EXPOSE 7860
|
||||
CMD ["node", "server.js"]
|
||||
```
|
||||
|
||||
### 2. Docker Compose
|
||||
Create a `docker-compose.yml` file:
|
||||
|
||||
### Docker Compose
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
@@ -76,28 +67,23 @@ services:
|
||||
max-file: "3"
|
||||
```
|
||||
|
||||
Start the container in detached mode:
|
||||
Start the container:
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Deployment Option 2: Direct Node.js & Systemd
|
||||
## Deployment Option 2: Systemd
|
||||
|
||||
### 1. Installation
|
||||
### 1. Install
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://gitlab.com/vyla-entertainment/stream-api.git /opt/stream-api
|
||||
cd /opt/stream-api
|
||||
|
||||
# Install dependencies
|
||||
npm ci --omit=dev
|
||||
```
|
||||
|
||||
### 2. Create Systemd Service
|
||||
Create `/etc/systemd/system/stream-api.service`:
|
||||
|
||||
### 2. Service File: `/etc/systemd/system/stream-api.service`
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Vyla Stream API Service
|
||||
@@ -115,7 +101,6 @@ Environment=PORT=7860
|
||||
Environment=TMDB_API_KEY=your_tmdb_api_key_here
|
||||
Environment=WORKER_COUNT=4
|
||||
|
||||
# Security Hardening
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=full
|
||||
@@ -124,7 +109,7 @@ ProtectSystem=full
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Enable and start the service:
|
||||
Enable and start:
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now stream-api
|
||||
@@ -133,34 +118,30 @@ sudo systemctl status stream-api
|
||||
|
||||
---
|
||||
|
||||
## Reverse Proxy: Nginx Configuration
|
||||
## Reverse Proxy: Nginx
|
||||
|
||||
Because Stream API utilizes **Server-Sent Events (SSE)** and large **HLS video streams**, your reverse proxy must disable proxy buffering. Standard buffering will delay SSE events until the buffer fills, breaking progressive playback.
|
||||
Disable proxy buffering so Server-Sent Events (SSE) stream progressively to clients.
|
||||
|
||||
Create an Nginx configuration at `/etc/nginx/sites-available/stream-api.conf`:
|
||||
Create `/etc/nginx/sites-available/stream-api.conf`:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
server_name stream-api.yourdomain.com;
|
||||
|
||||
# Maximum upload size for DB syncs
|
||||
client_max_body_size 20M;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:7860;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
# Mandatory for Server-Sent Events (SSE)
|
||||
proxy_set_header Connection '';
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
chunked_transfer_encoding off;
|
||||
|
||||
# Keep-Alive & Timeouts for long media streams
|
||||
proxy_read_timeout 90s;
|
||||
proxy_send_timeout 90s;
|
||||
|
||||
# Forward Client Identifiers for Geo-Token Verification
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
@@ -171,24 +152,20 @@ server {
|
||||
}
|
||||
```
|
||||
|
||||
Enable the configuration and obtain a free SSL certificate via Certbot:
|
||||
Enable and provision SSL:
|
||||
```bash
|
||||
sudo ln -s /etc/nginx/sites-available/stream-api.conf /etc/nginx/sites-enabled/
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
|
||||
# Install Let's Encrypt SSL
|
||||
sudo certbot --nginx -d stream-api.yourdomain.com
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Verifying Your Deployment
|
||||
## Health Check
|
||||
|
||||
Once deployed, verify the installation by testing the `/health` endpoint:
|
||||
Verify the deployment:
|
||||
|
||||
```bash
|
||||
curl -i https://stream-api.yourdomain.com/health
|
||||
```
|
||||
|
||||
You should receive an HTTP 200 (or 207) with JSON detailing the cluster status, cache count, and source probe results.
|
||||
|
||||
Reference in New Issue
Block a user