Skip to content

Commit

Permalink
Introduce proxy username, proxy password options for proxy auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
jszuminski committed Aug 21, 2024
1 parent e740944 commit 10865d4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ SERVER_BENCHMARKING = false
# SERVER PROXY CONFIG
SERVER_PROXY_HOST =
SERVER_PROXY_PORT =
SERVER_PROXY_USERNAME =
SERVER_PROXY_PASSWORD =
SERVER_PROXY_TIMEOUT = 5000

# SERVER RATE LIMITING CONFIG
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ These variables are set in your environment and take precedence over options fro

- `SERVER_PROXY_HOST`: The host of the proxy server to use, if it exists (defaults to ``).
- `SERVER_PROXY_PORT`: The port of the proxy server to use, if it exists (defaults to ``).
- `SERVER_PROXY_USERNAME`: If used proxy with authentication, need to pass username and password (optional, defaults to `false`).
- `SERVER_PROXY_PASSWORD`: If used proxy with authentication, need to pass username and password (optional, defaults to `false`).
- `SERVER_PROXY_TIMEOUT`: The timeout for the proxy server to use, if it exists (defaults to ``).

### Server Rate Limiting Config
Expand Down Expand Up @@ -414,6 +416,8 @@ _Available options:_
- `--serverBenchmarking`: Indicates whether to display the duration, in milliseconds, of specific actions that occur on the server while serving a request (defaults to `false`).
- `--proxyHost`: The host of the proxy server to use, if it exists (defaults to `false`).
- `--proxyPort`: The port of the proxy server to use, if it exists (defaults to `false`).
- `--proxyUsername`: If you want your proxy to be authenticated, pass the username with password (defaults to `false`).
- `--proxyPassword`: If you want your proxy to be authenticated, pass the username with password (defaults to `false`).
- `--proxyTimeout`: The timeout for the proxy server to use, if it exists (defaults to `5000`).
- `--enableRateLimiting`: Enables rate limiting for the server (defaults to `false`).
- `--maxRequests`: The maximum number of requests allowed in one minute (defaults to `10`).
Expand Down
10 changes: 5 additions & 5 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ export const fetchScripts = async (
) => {
// Configure proxy if exists
let proxyAgent;
const proxyHost = proxyOptions.host;
const proxyPort = proxyOptions.port;
const { host, port, username, password } = proxyOptions;

// Try to create a Proxy Agent
if (proxyHost && proxyPort) {
if (host && port) {
try {
proxyAgent = new HttpsProxyAgent({
host: proxyHost,
port: proxyPort
host,
port,
...(username && password ? { username, password } : {})
});
} catch (error) {
throw new ExportError('[cache] Could not create a Proxy Agent.').setError(
Expand Down
2 changes: 2 additions & 0 deletions lib/envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export const Config = z.object({
// server proxy
SERVER_PROXY_HOST: v.string(),
SERVER_PROXY_PORT: v.positiveNum(),
SERVER_PROXY_USERNAME: v.string(),
SERVER_PROXY_PASSWORD: v.string(),
SERVER_PROXY_TIMEOUT: v.nonNegativeNum(),

// server rate limiting
Expand Down
2 changes: 1 addition & 1 deletion lib/highcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function triggerExport(chartOptions, options, displayErrors) {
const userOptions = options.export.strInj
? new Function(`return ${options.export.strInj}`)()
: chartOptions;

// Trigger custom code
if (options.customLogic.customCode) {
new Function('options', options.customLogic.customCode)(userOptions);
Expand Down
14 changes: 14 additions & 0 deletions lib/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,20 @@ export const defaultConfig = {
cliName: 'proxyPort',
description: 'The port of the proxy server to use, if it exists.'
},
username: {
value: false,
type: 'string',
envLink: 'SERVER_PROXY_USERNAME',
cliName: 'proxyUsername',
description: 'The username for the proxy server, if it exists.'
},
password: {
value: false,
type: 'string',
envLink: 'SERVER_PROXY_PASSWORD',
cliName: 'proxyPassword',
description: 'The password for the proxy server, if it exists.'
},
timeout: {
value: 5000,
type: 'number',
Expand Down

0 comments on commit 10865d4

Please sign in to comment.