-
Notifications
You must be signed in to change notification settings - Fork 94
use proxy to download server resourece pack on any server #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
…t supporting cors url
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
WalkthroughThe changes improve error resilience in the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant R as downloadAndUseResourcePack
participant F as fetch(url)
participant P as fetch(proxy URL)
C->>R: Request resource pack
R->>F: Attempt primary fetch
alt Fetch Successful
F-->>R: Return resource pack data
R-->>C: Return data
else Fetch Fails
F-->>R: Error occurs
R->>P: Attempt fetch with fallback proxy URL
alt Fallback Successful
P-->>R: Return resource pack data
R-->>C: Return data
else Fallback Fails
P-->>R: Error occurs
R-->>C: Propagate error or handle failure
end
end
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
Scope: all 2 workspace projects Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/resourcePack.ts (1)
284-291
: Great addition of error handling with proxy fallback!This change improves resilience by adding a fallback mechanism when the direct fetch fails. The proxy URL allows downloading resource packs from servers that don't support CORS, which aligns well with the PR objectives.
Consider enhancing this implementation with:
try { response = await fetch(url) + if (!response.ok) { + throw new Error(`Failed to fetch resource pack: ${response.status} ${response.statusText}`) + } } catch (err) { + console.error('Error fetching resource pack directly:', 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?:\/\//, '')}`) + if (!response.ok) { + throw new Error(`Proxy fetch failed: ${response.status} ${response.statusText}`) + } }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/deploy
/deploy |
Deployed to Vercel Preview: https://prismarine-zcyjuuw2n-zaro.vercel.app |
// If direct URL fails, try proxy URL | ||
if (!response) { | ||
const urlWithoutProtocol = url.replace(/^https?:\/\//, '') | ||
const proxyUrl = `https://mcraft-proxy.vercel.app/0/${urlWithoutProtocol}` |
There was a problem hiding this comment.
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.
User description
…t supporting cors url
PR Type
Enhancement, Bug fix
Description
Added a fallback proxy for resource pack downloads.
Improved error handling for resource pack fetch failures.
Updated the proxy URL to use
mcraft-proxy.vercel.app
.Changes walkthrough 📝
resourcePack.ts
Add fallback proxy and improve fetch handling
src/resourcePack.ts
Summary by CodeRabbit