Skip to content

Commit

Permalink
feat(repeater): add PROXY and NO_PROXY env variables (#620)
Browse files Browse the repository at this point in the history
PROXY is an alias to --proxy flag
NO_PROXY is an alias to --proxy-domains-bypass flag

Co-authored-by: Or Rubin <or.rubin@hotmail.com>
  • Loading branch information
maksadbek and orubin authored Nov 26, 2024
1 parent 252e7f0 commit 340755a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/Commands/RunRepeater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DefaultRepeaterServerOptions, RepeaterLauncher } from '../Repeater';
import { Arguments, Argv, CommandModule } from 'yargs';
import { captureException } from '@sentry/node';
import { normalize } from 'node:path';
import process from 'node:process';

export class RunRepeater implements CommandModule {
public readonly command = 'repeater [options]';
Expand Down Expand Up @@ -135,13 +136,40 @@ export class RunRepeater implements CommandModule {
requiresArg: true,
array: true,
describe:
'Space-separated list of domains that should be routed through the proxy. This option is only applicable when using the --proxy option'
'Space-separated list of domains that should be routed through the proxy. This option is only applicable when using the --proxy option',
coerce(arg: string[]): string[] {
// if values are passed from env variable, they are passed as a single string
if (arg.length === 1) {
if (arg[0].includes(' ')) {
return arg[0].trim().split(' ');
}

return arg;
}

return arg;
}
})
.option('proxy-domains-bypass', {
requiresArg: true,
array: true,
default: process.env.NO_PROXY?.trim()
.split(',')
.map((domain) => domain.trim()),
describe:
'Space-separated list of domains that should not be routed through the proxy. This option is only applicable when using the --proxy option'
'Space-separated list of domains that should not be routed through the proxy. This option is only applicable when using the --proxy option',
coerce(arg: string[]): string[] {
// if values are passed from env variable, they are passed as a single string
if (arg.length === 1) {
if (arg[0].includes(' ')) {
return arg[0].trim().split(' ');
}

return arg;
}

return arg;
}
})
.conflicts({
daemon: 'remove-daemon',
Expand Down
2 changes: 2 additions & 0 deletions src/Config/CliBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CliInfo } from './CliInfo';
import { Arguments, Argv, CommandModule } from 'yargs';
import { init, runWithAsyncContext, setContext } from '@sentry/node';
import ms from 'ms';
import process from 'node:process';

export interface CliBuilderOptions {
info: CliInfo;
Expand Down Expand Up @@ -62,6 +63,7 @@ export class CliBuilder {
})
.option('proxy', {
requiresArg: true,
default: process.env.PROXY,
describe:
'Specify a proxy URL to route all traffic through. This should be an HTTP(S), SOCKS4, or SOCKS5 URL. By default, if you specify SOCKS://<URL>, then SOCKS5h is applied.'
})
Expand Down

0 comments on commit 340755a

Please sign in to comment.