diff --git a/cors-proxy/src/index.ts b/cors-proxy/src/index.ts index 641bbbf..1dc837c 100644 --- a/cors-proxy/src/index.ts +++ b/cors-proxy/src/index.ts @@ -210,7 +210,19 @@ const server = Bun.serve({ }); } - // Proxy the request + // Check if it's a YouTube URL and redirect instead of proxying + if (isYouTubeEmbed(targetUrl)) { + // YouTube URL detected, redirect to youtube-nocookie.com + logRequest(req.method, targetUrl, 200); + return new Response(serveYouTubeEmbed(targetUrl), { + status: 200, + headers: { + "Content-Type": "text/html; charset=utf-8", + }, + }); + } + + // Proxy the request for non-YouTube URLs const response = await proxyRequest(targetUrl); logRequest(req.method, targetUrl, response.status); return response; @@ -229,3 +241,80 @@ console.log( ); console.log(`📋 Health check: http://${server.hostname}:${server.port}/health`); console.log(`🌍 Environment: ${Bun.env.NODE_ENV || "development"}`); + +/** + * This is required to bypass YouTube's Referrer Policy restrictions when + * embedding videos on the mobile app. It basically "proxies" the Referrer and + * allows any YouTube video to be embedded anywhere without restrictions. + */ +function serveYouTubeEmbed(url: string) { + return ` + +
+ + + + +