Skip to content

Commit

Permalink
feat: properly parse proxy and allow-insecure options
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Aug 10, 2024
1 parent a3edb20 commit 583932f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { container } from '#lib/utils/container';
import { getProxyAgent } from '#lib/utils/getProxyAgent';
import { insertEnvVars } from '#lib/utils/insertEnvVars';
import { obfuscateWebhookUrl, UnboundWebhookRegex } from '#lib/utils/obfuscateWebhookUrl';
import { preflightChecks } from '#lib/utils/preflightChecks';
Expand All @@ -7,7 +8,6 @@ import { REST } from '@discordjs/rest';
import { MessageFlags, Routes, type RESTPostAPIWebhookWithTokenJSONBody } from 'discord-api-types/v10';
import { exit } from 'node:process';
import { inspect, parseArgs } from 'node:util';
import { ProxyAgent } from 'undici';

export type OptionsType = typeof values;

Expand Down Expand Up @@ -68,9 +68,7 @@ const checkedOptions = preflightChecks(values);

logResolvedOptions(checkedOptions);

const proxyAgent = typeof checkedOptions.proxy === 'string' ? new ProxyAgent(checkedOptions.proxy) : undefined;

const rest = new REST({ version: '10', agent: proxyAgent });
const rest = new REST({ version: '10', agent: getProxyAgent(checkedOptions) });

const webhookRegexResult = UnboundWebhookRegex.exec(checkedOptions['webhook-url']);

Expand Down
13 changes: 13 additions & 0 deletions src/lib/utils/getProxyAgent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { CheckedOptionsType } from '#lib/utils/preflightChecks';
import { ProxyAgent } from 'undici';

export function getProxyAgent(options: CheckedOptionsType): ProxyAgent | null {
if (!options.proxy && !options['allow-insecure']) return null;

return new ProxyAgent({
uri: options.proxy ?? '',
connect: {
rejectUnauthorized: !options['allow-insecure']
}
});
}

0 comments on commit 583932f

Please sign in to comment.