Skip to content

Commit 2c7f499

Browse files
authored
Merge branch 'master' into 563/async-example-readme
2 parents 6d193e5 + fd5edc3 commit 2c7f499

File tree

11 files changed

+108
-23
lines changed

11 files changed

+108
-23
lines changed

.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: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
<<<<<<< HEAD
2-
# 4.0.3
3-
4-
_Fixes:_
5-
6-
- Corrected the `Node.js Module` example in the README.
7-
=======
81
# 5.0.0
92

103
_Breaking Changes:_
@@ -18,7 +11,15 @@ _Fixes:_
1811
- Fixed an issue where the chart constructor was sometimes incorrectly set, causing the export to fail
1912
- Added referrers to CDN cache fetches on first startup/install.
2013
- Fixed an issue that would sometimes cause cause a crash due to fail due to `Accept-Ranges` headers
21-
>>>>>>> master
14+
- Corrected the `Node.js Module` example in the README.
15+
- Fixed the warning message when the the default `resources.json` file is not found.
16+
- Fixed the problem with the lack of the `instr` value, when the `options` is set instead
17+
18+
_New Features:_
19+
20+
- Added proxy authentication [(#631)](https://github.com/highcharts/node-export-server/issues/631).
21+
- 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).
22+
2223

2324
# 4.0.2
2425

README.md

Lines changed: 12 additions & 1 deletion
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`).

dist/index.cjs

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

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

lib/schemas/config.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ export const defaultConfig = {
146146
],
147147
type: 'string[]',
148148
description: 'Arguments array to send to Puppeteer.'
149+
},
150+
tempDir: {
151+
value: './tmp/',
152+
type: 'string',
153+
envLink: 'PUPPETEER_TEMP_DIR',
154+
description: 'The directory for Puppeteer to store temporary files.'
149155
}
150156
},
151157
highcharts: {
@@ -355,7 +361,6 @@ export const defaultConfig = {
355361
envLink: 'SERVER_MAX_UPLOAD_SIZE',
356362
description:
357363
'The maximum upload size, in megabytes, for the server'
358-
359364
},
360365
enable: {
361366
value: false,
@@ -401,6 +406,20 @@ export const defaultConfig = {
401406
cliName: 'proxyPort',
402407
description: 'The port of the proxy server to use, if it exists.'
403408
},
409+
username: {
410+
value: false,
411+
type: 'string',
412+
envLink: 'SERVER_PROXY_USERNAME',
413+
cliName: 'proxyUsername',
414+
description: 'The username for the proxy server, if it exists.'
415+
},
416+
password: {
417+
value: false,
418+
type: 'string',
419+
envLink: 'SERVER_PROXY_PASSWORD',
420+
cliName: 'proxyPassword',
421+
description: 'The password for the proxy server, if it exists.'
422+
},
404423
timeout: {
405424
value: 5000,
406425
type: 'number',

0 commit comments

Comments
 (0)