-
Notifications
You must be signed in to change notification settings - Fork 41
fix: localhost resolution error #227
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: master
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request modifies the Axios proxy configuration to add IPv4-specific DNS resolution for localhost in the non-Requestly proxy path. The changes include importing the http and https modules, implementing a localhostIPv4Lookup function to force IPv4 resolution, creating custom httpAgent and httpsAgent with this lookup function, and passing these agents to the Axios configuration. The Requestly proxy path retains its existing behavior unchanged. Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
…stom http agent instead
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 (2)
src/main/actions/getProxiedAxios.ts (2)
9-11: Use consistent import syntax.Line 9 uses CommonJS
require()while lines 10-11 use ES6importsyntax. Consider using ES6 imports consistently for better TypeScript integration and code clarity.Apply this diff for consistency:
-const dns = require("dns") +import dns from "dns"; import http from "http"; import https from "https";
54-60: Add proper type annotations to the lookup function.The function parameters are typed as
any, which reduces type safety. Consider using proper types from Node.js dns module.Apply this diff to add type annotations:
- const localhostIPv4Lookup = (hostname: any, options: any, callback: any) => { + const localhostIPv4Lookup = ( + hostname: string, + options: dns.LookupOneOptions, + callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void + ) => { if (hostname === 'localhost') { dns.lookup(hostname, { ...options, family: 4 }, callback); } else { dns.lookup(hostname, options, callback); } };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/actions/getProxiedAxios.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/actions/getProxiedAxios.ts (1)
src/main/actions/makeApiClientRequest.js (1)
axios(70-70)
🔇 Additional comments (3)
src/main/actions/getProxiedAxios.ts (3)
61-62: LGTM! Custom agents properly configured.The http and https agents are correctly instantiated with the custom
localhostIPv4Lookupfunction, ensuring IPv4-first resolution for localhost addresses.
63-67: LGTM! Axios instance correctly configured with custom agents.The custom agents are properly integrated into the Axios instance configuration for the non-RQ-proxy path, implementing the IPv4-first localhost resolution as intended.
54-60: No issues identified. The limited scope is intentional and correct.The
localhostIPv4Lookupfunction is specifically designed to handle the'localhost'hostname by forcing IPv4-only resolution. This is necessary because Node.js resolves'localhost'to both IPv4 (127.0.0.1) and IPv6 (::1) by default, and the proxy is only available on IPv4.Numeric IPv4 addresses like
127.0.0.1don't require special DNS lookup handling—they're already resolved. IPv6 loopback addresses (::1) are not used anywhere in the codebase, and no scenarios require their special handling.The design appropriately addresses the actual localhost resolution scenario in use.
httpProxyAgent(that we recently removed - [ONCALL-125] chore: stop api client request to be proxied #214) in the axios config was earlier managing the fallback to this and resolving through ipv4 for loopback addresses RefTwo ways to solve this could be:
verbatimtoipv4firstto force ipv4 resolution for all cases. but this would impact all requests and not just loopback address. hence, this might have unexpected consequencesThis PR proposes changes for the second approach
Summary by CodeRabbit