feat: add upstream proxy configuration for outbound requests#1458
feat: add upstream proxy configuration for outbound requests#1458Andreybest wants to merge 6 commits intofinos:mainfrom
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 canceled.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1458 +/- ##
=======================================
Coverage 89.66% 89.67%
=======================================
Files 68 68
Lines 4869 4947 +78
Branches 888 918 +30
=======================================
+ Hits 4366 4436 +70
- Misses 485 493 +8
Partials 18 18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jescalada
left a comment
There was a problem hiding this comment.
@Andreybest Thanks for the contribution! 🚀
I left some comments for code refactoring. It'd be very helpful if you could upload images or a video demonstrating that this feature works as intended.
@coopernetes Wondering if this implements your original requirements (#759) and works on your end 🤔
dcoric
left a comment
There was a problem hiding this comment.
Thanks for tackling #759. I've left a few comments focused on correctness and robustness, especially around NO_PROXY pattern handling which is important to get right for the target use case. The main items are the missing */leading-dot NO_PROXY support and proxy URL validation.
src/proxy/routes/index.ts
Outdated
| return undefined; | ||
| } | ||
|
|
||
| return new HttpsProxyAgent(proxyUrl); |
There was a problem hiding this comment.
The proxyUrl (from config or env vars) is passed directly to new HttpsProxyAgent(proxyUrl) without validation. If the URL is malformed (typo, missing protocol, empty string after trimming), this throws a cryptic Invalid URL error that surfaces through express-http-proxy's error handler with no indication that the upstream proxy config is the problem.
Consider wrapping this in a try-catch or validating first:
try {
new URL(proxyUrl); // validate before constructing agent
} catch {
throw new Error(`Invalid upstream proxy URL: check your upstreamProxy.url config or HTTPS_PROXY env var`);
}
return new HttpsProxyAgent(proxyUrl);There was a problem hiding this comment.
This comment might still need fixing! 🙂
|
Thanks for the reviews @jescalada and @dcoric! |
|
@jescalada Screen.Recording.2026-03-25.at.21.35.35_no_audio.mov |
Co-authored-by: Thomas Cooper <57812123+coopernetes@users.noreply.github.com> Signed-off-by: Andrew <andrey255@live.com>
jescalada
left a comment
There was a problem hiding this comment.
LGTM after fixing Denis' comment about validating/error handling the HttpsProxyAgent creation.
@coopernetes Does everything work as you expected? 🤔
|
|
||
| const getOrCreateProxyAgent = (proxyUrl: string): HttpsProxyAgent<string> => { | ||
| if (!_cachedProxyAgent || _cachedProxyAgent.proxyUrl !== proxyUrl) { | ||
| _cachedProxyAgent = { proxyUrl, agent: new HttpsProxyAgent(proxyUrl) }; |
There was a problem hiding this comment.
Just repeating Denis earlier comment - this should be properly validated and/or throw a descriptive error
src/proxy/routes/index.ts
Outdated
| return undefined; | ||
| } | ||
|
|
||
| return new HttpsProxyAgent(proxyUrl); |
There was a problem hiding this comment.
This comment might still need fixing! 🙂
Resolves #759.
Adds upstream proxy support. Uses values from both configuration file in
upstreamProxyfields and environment variables (HTTPS_PROXY/HTTP_PROXY,NO_PROXY)