diff --git a/components/player/MobileVideoPlayer.tsx b/components/player/MobileVideoPlayer.tsx
index 5076eab..e54746c 100644
--- a/components/player/MobileVideoPlayer.tsx
+++ b/components/player/MobileVideoPlayer.tsx
@@ -30,8 +30,14 @@ export function MobileVideoPlayer({
const { refs, state } = useMobilePlayerState();
const { currentTime } = state;
+ // Ensure src goes through proxy to avoid CORS/IP issues on Vercel
+ // But don't double-proxy if already proxied
+ const proxySrc = src.includes('/api/proxy')
+ ? src
+ : `${typeof window !== 'undefined' ? window.location.origin : ''}/api/proxy?url=${encodeURIComponent(src)}`;
+
// Preload HLS segments
- useHLSPreloader({ src, currentTime, videoRef: refs.videoRef, isLoading: state.isLoading });
+ useHLSPreloader({ src: proxySrc, currentTime, videoRef: refs.videoRef, isLoading: state.isLoading });
const {
videoRef,
@@ -54,7 +60,7 @@ export function MobileVideoPlayer({
} = state;
const logic = useMobilePlayerLogic({
- src,
+ src: proxySrc,
initialTime,
shouldAutoPlay,
onError,
@@ -98,7 +104,7 @@ export function MobileVideoPlayer({
{
@@ -117,12 +122,12 @@ export function useHlsPlayer({
} else {
console.log('[HLS] Using native HLS support');
// Native HLS support
- video.src = src;
+ video.src = proxySrc;
}
} else if (isNativeHlsSupported) {
// Fallback for environments where Hls.js is not supported but native is (e.g. iOS without MSE?)
console.log('[HLS] Using native HLS support (Hls.js not supported)');
- video.src = src;
+ video.src = proxySrc;
} else {
console.error('[HLS] HLS not supported in this browser');
}
diff --git a/lib/utils/fetch-with-retry.ts b/lib/utils/fetch-with-retry.ts
index 4ccc724..6284caf 100644
--- a/lib/utils/fetch-with-retry.ts
+++ b/lib/utils/fetch-with-retry.ts
@@ -20,8 +20,10 @@ export async function fetchWithRetry({ url, request }: FetchWithRetryOptions): P
// Optional IP forwarding (default: Beijing IP)
const forwardedIP = request.nextUrl.searchParams.get('ip') || '202.108.22.5';
- const MAX_RETRIES = 5;
- const TIMEOUT_MS = 30000; // 30 seconds
+ // Vercel serverless functions have a 10s default timeout
+ const isVercel = process.env.VERCEL === '1';
+ const MAX_RETRIES = isVercel ? 2 : 5;
+ const TIMEOUT_MS = isVercel ? 8000 : 30000; // 8s for Vercel, 30s for others
let lastError: unknown = null;
let response: Response | null = null;