diff --git a/docker-compose.yml b/docker-compose.yml index 0aa7715..906f05a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,8 @@ services: - .env environment: FRONTEND_URL: http://localhost + ports: + - "8080:8080" restart: unless-stopped frontend: @@ -35,18 +37,19 @@ services: VITE_GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID} depends_on: - backend + ports: + - "1935:1935" restart: unless-stopped - nginx: + rtmp: build: context: ./nginx dockerfile: Dockerfile - container_name: vod_nginx + container_name: vod_rtmp depends_on: - backend - frontend ports: - - "80:80" - "1935:1935" volumes: - ${STREAM_DATA}:/stream diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 92121a3..0ed9f1e 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -3,4 +3,3 @@ FROM tiangolo/nginx-rtmp COPY nginx.conf /etc/nginx/nginx.conf EXPOSE 1935 -EXPOSE 8080 diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 2b7e71a..98518a5 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -3,6 +3,15 @@ events { worker_connections 1024; } +upstream backend { + server 127.0.0.1:8080; +} + +upstream frontend { + server 127.0.0.1:5173; +} + + rtmp { server { listen 1935; @@ -23,61 +32,19 @@ rtmp { } } +# Serve the HLS segments over HTTP http { - sendfile off; - tcp_nopush on; - default_type application/octet-stream; - - # Allow large uploads (matches Spring Boot multipart limit) - client_max_body_size 2g; - server { - listen 80; + listen 8088; - # Spring Boot API - location /api/v1/ { - proxy_pass http://vod_backend:8080; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - - # Large upload timeouts - proxy_read_timeout 600s; - proxy_send_timeout 600s; - proxy_request_buffering off; - } - - # HLS stream playback location /hls { types { - application/vnd.apple.mpegurl m3u8; - video/mp2t ts; + application/vnd.apple.mpegurl m3u8; # proper MIME for HLS playlists + video/mp2t ts; # MPEG-TS segment MIME } root /tmp; - add_header Cache-Control no-cache; - add_header Access-Control-Allow-Origin *; - } - - # RTMP stats - location /stat { - rtmp_stat all; - rtmp_stat_stylesheet stat.xsl; - } - - location /stat.xsl { - root /usr/local/nginx/html; - } - - # Frontend (Vite dev server) — catch-all - location / { - proxy_pass http://vod_frontend:5173; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; + add_header Cache-Control no-cache; # prevent stale segments + add_header Access-Control-Allow-Origin *; # CORS for browser playback } } -} +} \ No newline at end of file diff --git a/src/main/resources/db/schema.sql b/src/main/resources/db/schema.sql index 076c547..c94b828 100644 --- a/src/main/resources/db/schema.sql +++ b/src/main/resources/db/schema.sql @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS streams; DROP TABLE IF EXISTS clips; DROP TABLE IF EXISTS users; @@ -10,7 +11,7 @@ CREATE TABLE IF NOT EXISTS users ( profile_picture_url VARCHAR(255), role INTEGER DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - stream_key VARCHAR(64) NOT NULL + stream_key VARCHAR(64) ); CREATE TABLE IF NOT EXISTS streams ( @@ -18,11 +19,10 @@ CREATE TABLE IF NOT EXISTS streams ( user_id BIGSERIAL, start_time TIMESTAMPTZ DEFAULT NOW(), end_time TIMESTAMPTZ DEFAULT NULL, - last_seen TIMESTAMPTZ DEFAULT NULL - + last_seen TIMESTAMPTZ DEFAULT NULL, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE -) +); CREATE TABLE IF NOT EXISTS clips ( id BIGSERIAL PRIMARY KEY,