Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

631/proxy-authentication #632

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ _Fixes:_
- Added referrers to CDN cache fetches on first startup/install.
- Fixed an issue that would sometimes cause cause a crash due to fail due to `Accept-Ranges` headers

_New Features:_

- Added proxy authentication [(#631)](https://github.com/highcharts/node-export-server/issues/631).

# 4.0.2

_Hotfix_:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ The format, along with its default values, is as follows (using the recommended
"proxy": {
"host": "",
"port": 8080,
"username": false,
"password": false,
"timeout": 5000
},
"rateLimiting": {
Expand Down Expand Up @@ -323,6 +325,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 (defaults to ``).
- `SERVER_PROXY_PASSWORD`: If used proxy with authentication, need to pass username and password (defaults to ``).
- `SERVER_PROXY_TIMEOUT`: The timeout for the proxy server to use, if it exists (defaults to ``).

### Server Rate Limiting Config
Expand Down Expand Up @@ -419,6 +423,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
4 changes: 2 additions & 2 deletions dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js.map

Large diffs are not rendered by default.

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
14 changes: 14 additions & 0 deletions lib/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading