Skip to content

Commit

Permalink
refactor: initialise EnvHttpProxyAgent only once
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Aug 25, 2024
1 parent 684b1e7 commit 13aad62
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ interface Options {
fetch?: any;
}

const proxyAgent = new EnvHttpProxyAgent()

class Client {
#source: string;
#target: string;
#fetch: typeof global.fetch;
#fetch: typeof undiciFetch;
#logger: Pick<Console, Severity>;
#events!: EventSource;

Expand All @@ -45,7 +47,7 @@ class Client {
const response = await fetch("https://smee.io/new", {
method: "HEAD",
redirect: "manual",
dispatcher: new EnvHttpProxyAgent(),
dispatcher: proxyAgent,
});
const address = response.headers.get("location");
if (!address) {
Expand Down Expand Up @@ -85,6 +87,7 @@ class Client {
mode: data["sec-fetch-mode"],
body,
headers,
dispatcher: proxyAgent,
});
this.#logger.info(`POST ${response.url} - ${response.status}`);
} catch (err) {
Expand All @@ -102,7 +105,7 @@ class Client {

start() {
const events = new EventSource(this.#source, {
dispatcher: new EnvHttpProxyAgent(),
dispatcher: proxyAgent,
});

// Reconnect immediately
Expand Down

0 comments on commit 13aad62

Please sign in to comment.