mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat: Refactor proxy configuration to use getRequestProxyAgents method across multiple modules
This commit is contained in:
@@ -44,10 +44,7 @@ router.get(
|
||||
requestBody,
|
||||
{},
|
||||
undefined,
|
||||
{
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
|
||||
if (result instanceof HTTPErrorResponse) {
|
||||
|
||||
@@ -40,10 +40,7 @@ const InitJob: VoidFunction = (): void => {
|
||||
URL.fromString(PROBE_INGEST_URL.toString()).addRoute("/alive"),
|
||||
ProbeAPIRequest.getDefaultRequestBody(),
|
||||
undefined,
|
||||
{
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
|
||||
@@ -102,10 +102,7 @@ class FetchListAndProbe {
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
|
||||
logger.debug("Fetched monitor list");
|
||||
|
||||
@@ -66,10 +66,7 @@ class FetchMonitorTestAndProbe {
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
|
||||
logger.debug("MONITOR TEST: Fetched monitor test list");
|
||||
|
||||
@@ -84,10 +84,7 @@ export default class Register {
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -136,10 +133,7 @@ export default class Register {
|
||||
clusterKey: ClusterKeyAuthorization.getClusterKey(),
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
@@ -164,10 +158,7 @@ export default class Register {
|
||||
probeId: PROBE_ID.toString(),
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
|
||||
LocalCache.setString("PROBE", "PROBE_ID", PROBE_ID.toString() as string);
|
||||
|
||||
@@ -75,10 +75,7 @@ export default class MonitorUtil {
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,10 +125,7 @@ export default class MonitorUtil {
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
},
|
||||
{ ...ProxyConfig.getRequestProxyAgents() },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,7 @@ export default class ApiMonitor {
|
||||
{
|
||||
timeout: options.timeout?.toNumber() || 5000,
|
||||
doNotFollowRedirects: options.doNotFollowRedirects || false,
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
...ProxyConfig.getRequestProxyAgents(),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -90,8 +89,7 @@ export default class ApiMonitor {
|
||||
{
|
||||
timeout: options.timeout?.toNumber() || 5000,
|
||||
doNotFollowRedirects: options.doNotFollowRedirects || false,
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
...ProxyConfig.getRequestProxyAgents(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -65,8 +65,7 @@ export default class WebsiteMonitor {
|
||||
isHeadRequest: options.isHeadRequest,
|
||||
timeout: options.timeout?.toNumber() || 5000,
|
||||
doNotFollowRedirects: options.doNotFollowRedirects || false,
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
...ProxyConfig.getRequestProxyAgents(),
|
||||
});
|
||||
|
||||
if (
|
||||
@@ -79,8 +78,7 @@ export default class WebsiteMonitor {
|
||||
isHeadRequest: false,
|
||||
timeout: options.timeout?.toNumber() || 5000,
|
||||
doNotFollowRedirects: options.doNotFollowRedirects || false,
|
||||
httpAgent: ProxyConfig.getHttpProxyAgent() || undefined,
|
||||
httpsAgent: ProxyConfig.getHttpsProxyAgent() || undefined,
|
||||
...ProxyConfig.getRequestProxyAgents(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -73,4 +73,25 @@ export default class ProxyConfig {
|
||||
return this.httpsProxyAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object containing httpAgent / httpsAgent suitable to spread into RequestOptions
|
||||
* or as part of WebsiteRequest.fetch options. If no proxy configured returns empty object.
|
||||
*/
|
||||
public static getRequestProxyAgents(): {
|
||||
httpAgent?: HttpProxyAgent<string>;
|
||||
httpsAgent?: HttpsProxyAgent<string>;
|
||||
} {
|
||||
if (!this.isProxyConfigured()) {
|
||||
return {};
|
||||
}
|
||||
const agents: { httpAgent?: any; httpsAgent?: any } = {};
|
||||
if (this.httpProxyAgent) {
|
||||
agents.httpAgent = this.httpProxyAgent;
|
||||
}
|
||||
if (this.httpsProxyAgent) {
|
||||
agents.httpsAgent = this.httpsProxyAgent;
|
||||
}
|
||||
return agents;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user