Skip to content

fix: proxy drops range headers and buffers video — breaks playback - #35

Merged
ricardogr07 merged 3 commits into
mainfrom
fix/proxy-video-streaming
Jun 25, 2026
Merged

ricardogr07 merged 3 commits into
mainfrom
fix/proxy-video-streaming

Conversation

@ricardogr07

Copy link
Copy Markdown
Owner

Summary

  • Root cause: The Next.js proxy forwarded only Content-Type, dropping the headers the browser needs for video streaming: Content-Range, Accept-Ranges, Content-Length. The browser received 206 but had no range metadata, so it couldn't render the video.
  • Secondary issue: arrayBuffer() buffered the full response before sending — 100 MB+ clips would stall or OOM under Vercel's function memory/timeout limits.
  • Fix: Stream upstream.body directly to the client and pass through the three range headers. Applies to all proxy responses (JSON unaffected — body is still streamed, just smaller).

Test plan

  • CI green
  • After deploy: open clipsmith-dashboard.vercel.app/runs/1, click a clip — video plays in modal
  • Confirm https://clipsmith-dashboard.vercel.app/api/runs/1/clips/file/clip_01_...mp4 loads video directly in browser

Two bugs preventing clips from playing in the dashboard:

1. fileUrl used DIRECT (http://api-ip:8000) — browsers block loading
   HTTP media from an HTTPS Vercel page (mixed-content policy).
   Fix: route file downloads through the same-origin Next.js proxy.

2. The proxy read all responses with upstream.text(), which corrupts
   binary MP4 data. Fix: use arrayBuffer() so binary passes through intact.
The Next.js proxy was not forwarding Content-Range, Accept-Ranges, or
Content-Length headers, so the browser received a 206 with no range
metadata and could not render the video.

Also, buffering the full response with arrayBuffer() would stall or OOM
on 100MB+ clips under Vercel's function limits.

Fix: stream upstream.body directly and pass through range headers.
@ricardogr07
ricardogr07 merged commit b521c60 into main Jun 25, 2026
7 checks passed
@ricardogr07
ricardogr07 deleted the fix/proxy-video-streaming branch June 25, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant