Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/resourcePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Copy link

@Phoenix616 Phoenix616 Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to use the proxy that is already used for the packets for the resource pack too? That way this centralised failure point could be prevented. Also you could prevent abuse of the proxy server as right now one can query other arbitrary files through that url (which might expose you to some legal issues too). If the webclient proxy would handle the pack proxying as well then it could cache which server resource packs actually got sent from the server and only allow proxying those.

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

Expand Down
Loading