feat(streaming): standalone media proxy server, footer, and configurable proxy origin - #19
Closed
harusharu wants to merge 1 commit into
Closed
feat(streaming): standalone media proxy server, footer, and configurable proxy origin#19harusharu wants to merge 1 commit into
harusharu wants to merge 1 commit into
Conversation
…ble proxy origin
Overview
--------
This change lets the streaming app work around provider CDNs that reject
Vercel's datacenter IPs (e.g. the Aliyun OSS host behind themoviebox.org
returns HTTP 403 for cloud IPs). It introduces a self-contained, Node-only
media proxy server that can run on a VPS or home server with a residential
(non-blocked) IP, while keeping the exact same /api/proxy protocol the
player already uses. In addition, it adds a compact site footer and tidies
up tooling config.
Highlights
----------
1. Standalone proxy server (server/proxy.ts)
- Implements /api/proxy with the same query contract as the Next.js
route handler (url + referer/origin/userAgent/cookie header params),
plus a /health endpoint for uptime checks.
- Reuses the shared proxyStream() module from src/lib/media so rewrite
and header-injection logic stays in a single place.
- Supports Range requests, HEAD requests, upstream AbortController
cancellation on client disconnect, and absolute URL rewriting of HLS
manifests via a new `origin` option so segments/keys resolve back to
the proxy server (not the app origin).
- Maps upstream failures to meaningful status codes (502 by default,
passes through 4xx/5xx from the provider).
2. esbuild bundling script (scripts/build-proxy.mjs)
- Bundles server/proxy.ts into a single self-contained
dist/proxy-server.cjs with the `@/` alias resolved to src/, targeting
Node 22. The artifact needs no node_modules or Next.js at runtime.
- Adds pnpm scripts: build:proxy and start:proxy; wires esbuild into
pnpm-workspace allowBuilds.
3. Configurable proxy origin
- playbackUrl() in src/lib/media/playback.ts now honors
NEXT_PUBLIC_STREAM_PROXY_URL; when set, generated /api/proxy URLs
point at the external proxy, otherwise they stay same-origin.
- proxiedUrl() and rewriteHlsManifest() in streamProxy.ts accept an
`origin` param to emit absolute rewritten HLS URLs for the standalone
deployment.
- .env.example documents the new optional var.
4. Site footer (src/components/layout/Footer.tsx)
- Compact, two-row footer with GitHub repo, "Report an issue", and
license links, plus an AGPL-3.0 copyright line noting third-party
streaming sources. Rendered once in App.tsx using the existing
viewFadeUp animation primitives.
5. Tooling & housekeeping
- biome.json now ignores the .agents directory (vendored skills data
shouldn't be linted/formatted).
- .gitignore ignores dist/ (proxy build artifact).
- next-env.d.ts refreshed to the .next/types route types.
- Regenerated skills-lock.json hash and pnpm-lock.yaml entries.
Notes
-----
- No runtime behavior changes for existing deployments unless
NEXT_PUBLIC_STREAM_PROXY_URL is set.
- The .agents data fixtures were re-generated by their skill update tooling
(large data churn is expected and intentional).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Owner
Author
|
Abandoning this approach; will rework streaming proxy strategy separately. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes the streaming app able to play sources from provider CDNs that block Vercel's datacenter IPs (e.g. the Aliyun OSS host behind themoviebox.org returns
403 Forbiddenfor cloud IPs). It adds a self-contained, Node-only media proxy server that can run on a VPS/home server with a residential IP, reusing the exact same/api/proxyprotocol the player already speaks. It also introduces a compact site footer and tidies up a few tooling configs.What's included
1. Standalone proxy server —
server/proxy.ts/api/proxywith the same query contract as the in-function route handler (url+ optionalreferer/origin/userAgent/cookieheader params), plus a/healthendpoint.proxyStream()fromsrc/lib/media/streamProxyso manifest rewriting and header injection live in one place.Rangerequests,HEADrequests, and cancels the upstream fetch (AbortController) when the client disconnects so long streams don't leak connections.originoption) so segments/keys resolve correctly in the standalone deployment.502).2. esbuild bundling —
scripts/build-proxy.mjsserver/proxy.tsinto a single self-containeddist/proxy-server.cjs(Node 22 target,@/alias resolved tosrc/). The artifact runs with just Node — nonode_modules, no Next.js.pnpm build:proxyandpnpm start:proxy.esbuildadded to devDependencies and its build script allowed inpnpm-workspace.yaml(allowBuilds).3. Configurable proxy origin
playbackUrl()insrc/lib/media/playback.tsnow honorsNEXT_PUBLIC_STREAM_PROXY_URL. When set, generated media URLs point at the external proxy; when unset, playback stays same-origin (/api/proxy).proxiedUrl()/rewriteHlsManifest()instreamProxy.tsaccept anoriginparam to emit absolute rewritten HLS URLs for the standalone deployment..env.exampledocuments the new optional variable.4. Site footer —
src/components/layout/Footer.tsxApp.tsx, animated with the existingviewFadeUp/VIEWPORTprimitives.5. Tooling & housekeeping
biome.json: ignore the.agentsdirectory (vendored skill data shouldn't be linted/formatted)..gitignore: ignoredist/(proxy build artifact).next-env.d.ts: refreshed to the.next/typesroute types.skills-lock.json+pnpm-lock.yamlregenerated..agentsre-generated by their update tooling (large data churn is expected/intentional).Testing / how to verify
pnpm dev— playback uses/api/proxyas before. No behavior change without env config.NEXT_PUBLIC_STREAM_PROXY_URL=https://your-host.example.pnpm typecheckandpnpm lintto confirm nothing regressed.Notes