index.js
1 // This file is a placeholder to ensure that requests to /watch/index.js are redirected to /app/index.js 2 // The actual redirection is handled by the index.html file in this directory 3 console.warn('This file should not be executed directly. Redirecting to the correct location...'); 4 5 try { 6 // Create a URL object to properly handle the redirection while preserving query parameters 7 const currentUrl = new URL(window.location.href); 8 9 // Replace /watch/ with /app/ in the path 10 const newPath = currentUrl.pathname.replace(/^\/watch(\/|$)/, '/app$1'); 11 12 // Update the pathname while preserving the query parameters 13 currentUrl.pathname = newPath; 14 15 // Redirect to the new URL 16 console.info(`Redirecting from ${window.location.pathname} to ${newPath} (with query params: ${currentUrl.search})`); 17 window.location.href = currentUrl.toString(); 18 } catch (error) { 19 // Fallback to simple string replacement if URL parsing fails 20 console.error('Error during URL redirection:', error); 21 window.location.href = window.location.href.replace(/^(.*?)\/watch\//, '$1/app/'); 22 }