From da0829245fe754f3ae967ddd9321ff7ab03c92c7 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 18 Jul 2024 23:40:32 +0300 Subject: [PATCH] server-esm: Handle proxy agent --- src/services/request.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/services/request.ts b/src/services/request.ts index fe057024c..687e686d8 100644 --- a/src/services/request.ts +++ b/src/services/request.ts @@ -33,7 +33,7 @@ interface Client { request(opts: ClientOpts): Request; } -function exec(opts: ExecOpts): Promise { +async function exec(opts: ExecOpts): Promise { const client = getClient(opts); // hack for cases where electron.net does not work, but we don't want to set proxy @@ -47,7 +47,7 @@ function exec(opts: ExecOpts): Promise { requestId: 'n/a' }; - const proxyAgent = getProxyAgent(opts); + const proxyAgent = await getProxyAgent(opts); const parsedTargetUrl = url.parse(opts.url); return new Promise((resolve, reject) => { @@ -137,7 +137,7 @@ function exec(opts: ExecOpts): Promise { }); } -function getImage(imageUrl: string): Promise { +async function getImage(imageUrl: string): Promise { const proxyConf = syncOptions.getSyncProxy(); const opts: ClientOpts = { method: 'GET', @@ -146,7 +146,7 @@ function getImage(imageUrl: string): Promise { }; const client = getClient(opts); - const proxyAgent = getProxyAgent(opts); + const proxyAgent = await getProxyAgent(opts); const parsedTargetUrl = url.parse(opts.url); return new Promise((resolve, reject) => { @@ -189,7 +189,7 @@ function getImage(imageUrl: string): Promise { const HTTP = 'http:', HTTPS = 'https:'; -function getProxyAgent(opts: ClientOpts) { +async function getProxyAgent(opts: ClientOpts) { if (!opts.proxy) { return null; } @@ -201,8 +201,8 @@ function getProxyAgent(opts: ClientOpts) { } const AgentClass = HTTP === protocol - ? require('http-proxy-agent').HttpProxyAgent - : require('https-proxy-agent').HttpsProxyAgent; + ? (await import('http-proxy-agent')).HttpProxyAgent + : (await import('https-proxy-agent')).HttpsProxyAgent; return new AgentClass(opts.proxy); }