Summary: Also: - Move ProxyAgent to from app/server/utils to app/server/lib, which is the more usual place for such classes. - Refactor a helper (delayAbort) that node was reporting a leak in. Test Plan: Added a test case, and tested manually. Reviewers: JakubSerafin Reviewed By: JakubSerafin Subscribers: JakubSerafin, paulfitz Differential Revision: https://phab.getgrist.com/D3897pull/520/head
parent
84854b7cfa
commit
be5cb9124a
@ -0,0 +1,26 @@
|
|||||||
|
import {HttpsProxyAgent} from "https-proxy-agent";
|
||||||
|
import {HttpProxyAgent} from "http-proxy-agent";
|
||||||
|
import log from 'app/server/lib/log';
|
||||||
|
|
||||||
|
export function proxyAgent(requestUrl: URL): HttpProxyAgent | HttpsProxyAgent | undefined {
|
||||||
|
const proxy = process.env.GRIST_HTTPS_PROXY;
|
||||||
|
if (!proxy) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const ProxyAgent = requestUrl.protocol === "https:" ? HttpsProxyAgent : HttpProxyAgent;
|
||||||
|
const agent = new ProxyAgent(proxy);
|
||||||
|
|
||||||
|
// Wrap the main method of ProxyAgent into a wrapper that logs errors.
|
||||||
|
const callback = agent.callback;
|
||||||
|
agent.callback = async function () {
|
||||||
|
try {
|
||||||
|
return await callback.apply(this, arguments as any);
|
||||||
|
} catch (e) {
|
||||||
|
// Include info helpful for diagnosing issues (but not the potentially sensitive full requestUrl).
|
||||||
|
log.rawWarn(`ProxyAgent error ${e}`,
|
||||||
|
{proxy, reqProtocol: requestUrl.protocol, requestOrigin: requestUrl.origin});
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return agent;
|
||||||
|
}
|
@ -1,11 +0,0 @@
|
|||||||
import {HttpsProxyAgent} from "https-proxy-agent";
|
|
||||||
import {HttpProxyAgent} from "http-proxy-agent";
|
|
||||||
|
|
||||||
export function proxyAgent(requestUrl: URL): HttpProxyAgent | HttpsProxyAgent | undefined {
|
|
||||||
const proxy = process.env.GRIST_HTTPS_PROXY;
|
|
||||||
if (!proxy) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
const ProxyAgent = requestUrl.protocol === "https:" ? HttpsProxyAgent : HttpProxyAgent;
|
|
||||||
return new ProxyAgent(proxy);
|
|
||||||
}
|
|
Loading…
Reference in new issue