Skip to content

Commit 53a2e2f

Browse files
authored
Merge branch 'master' into enhancement/dev-tools-protocol-limit
2 parents 705c6df + 69ea56b commit 53a2e2f

12 files changed

Lines changed: 122 additions & 27 deletions

File tree

.env.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# PUPPETEER CONFIG
2+
PUPPETEER_TEMP_DIR = ./tmp/
3+
14
# HIGHCHARTS CONFIG
25
HIGHCHARTS_VERSION = latest
36
HIGHCHARTS_CDN_URL = https://code.highcharts.com/
@@ -29,6 +32,8 @@ SERVER_BENCHMARKING = false
2932
# SERVER PROXY CONFIG
3033
SERVER_PROXY_HOST =
3134
SERVER_PROXY_PORT =
35+
SERVER_PROXY_USERNAME =
36+
SERVER_PROXY_PASSWORD =
3237
SERVER_PROXY_TIMEOUT = 5000
3338

3439
# SERVER RATE LIMITING CONFIG

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ _Fixes:_
1313
- Fixed an issue that would sometimes cause cause a crash due to fail due to `Accept-Ranges` headers
1414
- Wrapped the `clearPageResources` function in a try-catch to handle potential page resources errors.
1515
- Secured against errors caused by `dev-tools` protocol data size limitations.
16+
- Corrected the `Node.js Module` example in the README.
17+
- Fixed the warning message when the the default `resources.json` file is not found.
18+
- Fixed the problem with the lack of the `instr` value, when the `options` is set instead
19+
20+
_New Features:_
21+
22+
- Added proxy authentication [(#631)](https://github.com/highcharts/node-export-server/issues/631).
23+
- Made the temporary Puppeteer directory (`PUPPETEER_TEMP_DIR`) (till now, `'./tmp'`) configurable by the user [(#567)](https://github.com/highcharts/node-export-server/issues/567).
1624

1725
# 4.0.2
1826

README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ The format, along with its default values, is as follows (using the recommended
9898
```
9999
{
100100
"puppeteer": {
101-
"args": []
101+
"args": [],
102+
"tempDir": "./tmp/"
102103
},
103104
"highcharts": {
104105
"version": "latest",
@@ -218,6 +219,8 @@ The format, along with its default values, is as follows (using the recommended
218219
"proxy": {
219220
"host": "",
220221
"port": 8080,
222+
"username": false,
223+
"password": false,
221224
"timeout": 5000
222225
},
223226
"rateLimiting": {
@@ -286,6 +289,10 @@ To load an additional JSON configuration file, use the `--loadConfig <filepath>`
286289

287290
These variables are set in your environment and take precedence over options from the `lib/schemas/config.js` file. They can be set in the `.env` file (refer to the `.env.sample` file). If you prefer setting these variables through the `package.json`, use `export` command on Linux/Mac OS X and `set` command on Windows.
288291

292+
### Puppeteer Config
293+
294+
- `PUPPETEER_TEMP_DIR`: The directory for Puppeteer to store temporary files (defaults to `./tmp/`).
295+
289296
### Highcharts Config
290297

291298
- `HIGHCHARTS_VERSION`: Highcharts version to use (defaults to `latest`).
@@ -323,6 +330,8 @@ These variables are set in your environment and take precedence over options fro
323330

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

328337
### Server Rate Limiting Config
@@ -419,6 +428,8 @@ _Available options:_
419428
- `--serverBenchmarking`: Indicates whether to display the duration, in milliseconds, of specific actions that occur on the server while serving a request (defaults to `false`).
420429
- `--proxyHost`: The host of the proxy server to use, if it exists (defaults to `false`).
421430
- `--proxyPort`: The port of the proxy server to use, if it exists (defaults to `false`).
431+
- `--proxyUsername`: If you want your proxy to be authenticated, pass the username with password (defaults to `false`).
432+
- `--proxyPassword`: If you want your proxy to be authenticated, pass the username with password (defaults to `false`).
422433
- `--proxyTimeout`: The timeout for the proxy server to use, if it exists (defaults to `5000`).
423434
- `--enableRateLimiting`: Enables rate limiting for the server (defaults to `false`).
424435
- `--maxRequests`: The maximum number of requests allowed in one minute (defaults to `10`).
@@ -573,20 +584,23 @@ const options = {
573584
}
574585
};
575586
576-
// Initialize export settings with your chart's config
577-
const exportSettings = exporter.setOptions(options);
587+
// Logic must be triggered in an asynchronous function
588+
(async () => {
589+
// Initialize export settings with your chart's config
590+
const exportSettings = exporter.setOptions(options);
578591
579-
// Must initialize exporting before being able to export charts
580-
await exporter.initExport(exportSettings);
592+
// Must initialize exporting before being able to export charts
593+
await exporter.initExport(exportSettings);
581594
582-
// Perform an export
583-
await exporter.startExport(exportSettings, async (error, info) => {
584-
// The export result is now in info
585-
// It will be base64 encoded (info.data)
595+
// Perform an export
596+
await exporter.startExport(exportSettings, async (error, info) => {
597+
// The export result is now in info
598+
// It will be base64 encoded (info.result)
586599
587-
// Kill the pool when we are done with it
588-
await exporter.killPool();
589-
});
600+
// Kill the pool when we are done with it
601+
await exporter.killPool();
602+
});
603+
})();
590604
```
591605

592606
## CommonJS support

dist/index.cjs

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

dist/index.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.esm.js.map

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ export function get() {
5959
*/
6060
export async function create(puppeteerArgs) {
6161
// Get debug and other options
62-
const { debug, other } = getOptions();
62+
const { puppeteer: puppeteerOptions, debug, other } = getOptions();
6363

6464
// Get the debug options
6565
const { enable: enabledDebug, ...debugOptions } = debug;
6666

6767
const launchOptions = {
6868
headless: other.browserShellMode ? 'shell' : true,
69-
userDataDir: './tmp/',
69+
userDataDir: puppeteerOptions.tempDir || './tmp/',
7070
args: puppeteerArgs,
7171
handleSIGINT: false,
7272
handleSIGTERM: false,

lib/cache.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ export const fetchScripts = async (
174174
) => {
175175
// Configure proxy if exists
176176
let proxyAgent;
177-
const proxyHost = proxyOptions.host;
178-
const proxyPort = proxyOptions.port;
177+
const { host, port, username, password } = proxyOptions;
179178

180179
// Try to create a Proxy Agent
181-
if (proxyHost && proxyPort) {
180+
if (host && port) {
182181
try {
183182
proxyAgent = new HttpsProxyAgent({
184-
host: proxyHost,
185-
port: proxyPort
183+
host,
184+
port,
185+
...(username && password ? { username, password } : {})
186186
});
187187
} catch (error) {
188188
throw new ExportError('[cache] Could not create a Proxy Agent.').setError(

lib/chart.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ export const startExport = async (settings, endCallback) => {
9797
try {
9898
log(4, '[chart] Attempting to export from a raw input.');
9999

100+
// Use whichever one is available
101+
exportOptions.instr = exportOptions.instr || exportOptions.options;
102+
100103
// Perform a direct inject when forced
101104
if (toBoolean(options.customLogic?.allowCodeExecution)) {
102105
return doStraightInject(options, endCallback);
@@ -321,11 +324,7 @@ const doExport = async (options, chartJson, endCallback, svg) => {
321324
toBoolean(options.customLogic.allowFileResources)
322325
);
323326
} catch (error) {
324-
logWithStack(
325-
2,
326-
error,
327-
`[chart] Unable to load the default resources.json file.`
328-
);
327+
log(2, `[chart] Unable to load the default resources.json file.`);
329328
}
330329
}
331330
}

lib/envs.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ const v = {
6464
)
6565
.transform((value) => (value !== '' ? value : undefined)),
6666

67+
// Checks if the string is a valid path directory (path format)
68+
path: () =>
69+
z
70+
.string()
71+
.trim()
72+
.refine(
73+
(value) => {
74+
// Simplified regex to match both absolute and relative paths
75+
return /^(\.\/|\.\.\/|\/|[a-zA-Z]:\\|[a-zA-Z]:\/)?(([\w]+|-)[\\/]?)+$/.test(
76+
value
77+
);
78+
},
79+
{},
80+
{
81+
message: 'The string is an invalid path directory string.'
82+
}
83+
),
84+
6785
// Allows positive numbers or no value in which case the returned value will
6886
// be undefined
6987
positiveNum: () =>
@@ -96,6 +114,9 @@ const v = {
96114
};
97115

98116
export const Config = z.object({
117+
// puppeteer
118+
PUPPETEER_TEMP_DIR: v.string(),
119+
99120
// highcharts
100121
HIGHCHARTS_VERSION: z
101122
.string()
@@ -148,6 +169,8 @@ export const Config = z.object({
148169
// server proxy
149170
SERVER_PROXY_HOST: v.string(),
150171
SERVER_PROXY_PORT: v.positiveNum(),
172+
SERVER_PROXY_USERNAME: v.string(),
173+
SERVER_PROXY_PASSWORD: v.string(),
151174
SERVER_PROXY_TIMEOUT: v.nonNegativeNum(),
152175

153176
// server rate limiting

0 commit comments

Comments
 (0)