mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
NEXT_PUBLIC_BUNNY_CDN_URL is inlined into the client bundle at build time, and the published image is built by CI without it, so the browser had no host to build a playlist URL from no matter what the operator set in .env.docker. The player read the empty URL as a stream that had not finished encoding and sat on 'Video Is Processing', retrying forever. The server knows the value on every request, so the root layout now serialises the public settings into a JSON script tag and the browser reads them from there, falling back to the build-time variable for source builds. The direct-download allow list came through the same broken path and moves with it. Closes #60
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { readRuntimePublicConfig } from '@/lib/runtime-public-config';
|
|
|
|
function normalizeBunnyCdnHostname(raw: string | null | undefined): string | null {
|
|
if (!raw) return null;
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) return null;
|
|
|
|
try {
|
|
const parsed = new URL(trimmed);
|
|
return parsed.hostname || null;
|
|
} catch {
|
|
return trimmed.replace(/^https?:\/\//, '').replace(/\/+$/, '') || null;
|
|
}
|
|
}
|
|
|
|
export function resolveServerBunnyCdnHostname(): string | null {
|
|
return normalizeBunnyCdnHostname(
|
|
process.env.BUNNY_CDN_URL || process.env.NEXT_PUBLIC_BUNNY_CDN_URL
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Browser-side hostname. Prefers the config the server injects at request time,
|
|
* because `NEXT_PUBLIC_BUNNY_CDN_URL` is inlined when the bundle is built and the
|
|
* published Docker image is built without it. Falls back to the build-time variable,
|
|
* which is what a source build sets, and to the server-only variable during the SSR
|
|
* pass of a client component, where it is still readable and has to produce the same
|
|
* hostname the browser will read or hydration diverges.
|
|
*/
|
|
export function resolvePublicBunnyCdnHostname(): string | null {
|
|
return (
|
|
normalizeBunnyCdnHostname(readRuntimePublicConfig()?.bunnyCdnUrl) ??
|
|
resolveServerBunnyCdnHostname()
|
|
);
|
|
}
|