From a7bf484880696fa10741edb307076989c191246f Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Fri, 20 Dec 2024 23:18:53 +0300 Subject: [PATCH 1/2] use proxy to download server resourece pack on any server from any not supporting cors url --- src/resourcePack.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/resourcePack.ts b/src/resourcePack.ts index 0ab9ec493..5ed6b40dd 100644 --- a/src/resourcePack.ts +++ b/src/resourcePack.ts @@ -281,7 +281,14 @@ const prepareBlockstatesAndModels = async () => { const downloadAndUseResourcePack = async (url: string): Promise => { console.log('Downloading server resource pack', url) - const response = await fetch(url) + let response + try { + response = await fetch(url) + } catch (err) { + // use fallback proxy (intended to be used as last resort on prod) + // response = await fetch(`https://cors-anywhere.herokuapp.com/${url.replace(/^https?:\/\//, '')}`) + response = await fetch(`https://mcraft-proxy.vercel.app/0/${url.replace(/^https?:\/\//, '')}`) + } const resourcePackData = await response.arrayBuffer() showNotification('Installing resource pack...') installTexturePack(resourcePackData, undefined, undefined, true).catch((err) => { From e51e0e926ac67c94d9e5e1d2189eff63badc8dab Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Fri, 14 Mar 2025 04:58:21 +0300 Subject: [PATCH 2/2] so damn clean cursor impl --- src/resourcePack.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/resourcePack.ts b/src/resourcePack.ts index fd01168a1..11354b0e3 100644 --- a/src/resourcePack.ts +++ b/src/resourcePack.ts @@ -389,11 +389,26 @@ const downloadAndUseResourcePack = async (url: string, progressReporter: Progres progressReporter.beginStage('download-resource-pack', 'Downloading server resource pack') console.log('Downloading server resource pack', url) console.time('downloadServerResourcePack') - const response = await fetch(url).catch((err) => { + + // Try direct URL first + let response = await fetch(url).catch((err) => { console.log(`Ensure server on ${url} support CORS which is not required for regular client, but is required for the web client`) console.error(err) - progressReporter.error('Failed to download resource pack: ' + err.message) + return null }) + + // If direct URL fails, try proxy URL + if (!response) { + const urlWithoutProtocol = url.replace(/^https?:\/\//, '') + const proxyUrl = `https://mcraft-proxy.vercel.app/0/${urlWithoutProtocol}` + console.log('Trying fallback proxy URL:', proxyUrl) + response = await fetch(proxyUrl).catch((err) => { + console.error('Proxy fetch also failed:', err) + progressReporter.error('Failed to download resource pack: ' + err.message) + return null + }) + } + console.timeEnd('downloadServerResourcePack') if (!response) return