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

feat/proxy-authentication #573

Closed
wants to merge 14 commits into from
Closed
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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# 4.0.2

_Hotfix_:

- Fixed missing 'msg' and 'public' bundle in 4.0.1 on NPM.

_Fixes:_

- Made chart userOptions available within `customCode` as variable `options` [(#551)](https://github.com/highcharts/node-export-server/issues/551).

# 4.0.1

_Hotfix_:

- Fixed missing 'dist' bundle in 4.0.0 on NPM.

# 4.0.0

_Breaking Changes:_
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
10 changes: 5 additions & 5 deletions lib/highcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ export async function triggerExport(chartOptions, options, displayErrors) {
// prevent from polluting other exports that can happen on the same page
Highcharts.setOptionsObj = merge(false, {}, getOptions());

// Trigger custom code
if (options.customLogic.customCode) {
new Function(options.customLogic.customCode)();
}

// By default animation is disabled
const chart = {
animation: false
Expand Down Expand Up @@ -101,6 +96,11 @@ export async function triggerExport(chartOptions, options, displayErrors) {
? new Function(`return ${options.export.strInj}`)()
: chartOptions;

// Trigger custom code
if (options.customLogic.customCode) {
new Function('options', options.customLogic.customCode)(userOptions);
}

// Merge the globalOptions, themeOptions, options from the wrapped
// setOptions function and user options to create the final options object
const finalOptions = merge(
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
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.

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Highsoft AS <[email protected]> (http://www.highcharts.com/about)",
"license": "MIT",
"type": "module",
"version": "4.0.0",
"version": "4.0.2",
"main": "./dist/index.esm.js",
"engines": {
"node": ">=18.12.0"
Expand All @@ -14,6 +14,15 @@
"require": "./dist/index.cjs"
}
},
"files": [
"dist",
"bin",
"templates",
"install.js",
"lib",
"msg",
"public"
],
"repository": {
"url": "https://github.com/highcharts/node-export-server",
"type": "git"
Expand All @@ -35,6 +44,7 @@
"node-tests": "node ./tests/node/node_test_runner.js",
"node-tests-single": "node ./tests/node/node_test_runner_single.js",
"prepare": "husky || true",
"prepack": "npm run build",
"build": "rollup -c",
"unit:test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
},
Expand Down
Loading