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

fix/parsing-envs #513

Merged
merged 4 commits into from
Apr 11, 2024
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
28 changes: 13 additions & 15 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# NODE ENVIRONMENT CONFIG
NODE_ENV = development

# HIGHCHARTS CONFIG
HIGHCHARTS_VERSION = latest
HIGHCHARTS_CDN_URL = https://code.highcharts.com/
HIGHCHARTS_CORE_SCRIPTS =
HIGHCHARTS_MODULES =
HIGHCHARTS_INDICATORS =
HIGHCHARTS_MODULE_SCRIPTS =
HIGHCHARTS_INDICATOR_SCRIPTS =
HIGHCHARTS_FORCE_FETCH = false
HIGHCHARTS_CACHE_PATH =
HIGHCHARTS_ADMIN_TOKEN =
Expand All @@ -29,11 +26,10 @@ SERVER_HOST = 0.0.0.0
SERVER_PORT = 7801
SERVER_BENCHMARKING = false

# SERVER SSL CONFIG
SERVER_SSL_ENABLE = false
SERVER_SSL_FORCE = false
SERVER_SSL_PORT = 443
SERVER_SSL_CERT_PATH =
# SERVER PROXY CONFIG
SERVER_PROXY_HOST =
SERVER_PROXY_PORT =
SERVER_PROXY_TIMEOUT = 5000

# SERVER RATE LIMITING CONFIG
SERVER_RATE_LIMITING_ENABLE = false
Expand All @@ -44,6 +40,12 @@ SERVER_RATE_LIMITING_TRUST_PROXY = false
SERVER_RATE_LIMITING_SKIP_KEY =
SERVER_RATE_LIMITING_SKIP_TOKEN =

# SERVER SSL CONFIG
SERVER_SSL_ENABLE = false
SERVER_SSL_FORCE = false
SERVER_SSL_PORT = 443
SERVER_SSL_CERT_PATH =

# POOL CONFIG
POOL_MIN_WORKERS = 4
POOL_MAX_WORKERS = 8
Expand All @@ -67,9 +69,5 @@ UI_ENABLE = true
UI_ROUTE = /

# OTHER CONFIG
OTHER_NODE_ENV = production
OTHER_NO_LOGO = false

# PROXY CONFIG
PROXY_SERVER_HOST =
PROXY_SERVER_PORT =
PROXY_SERVER_TIMEOUT =
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ _Enhancements:_
- Added unit tests for certain parts of the code.
- Changed the `customCode` section of options to `customLogic` in order to avoid confusion with the existing `customCode` property within.
- Changed the names of environment variables for a better representation of their roles (refer to all envs in the README's `Environment Variables` section).
- Added parsing of envs based on `zod` package.
- Added a new section to the server configuration options, `proxy`, along with corresponding environment variables.
- Added a moving average indicator for the exporting success rate ratio.
- Added new environment variables (`NODE_ENV`, `HIGHCHARTS_ADMIN_TOKEN`, and `SERVER_BENCHMARKING`) to the `.env.sample` file, along with their descriptions in the README.
- Added new environment variables (`HIGHCHARTS_ADMIN_TOKEN`, `SERVER_BENCHMARKING`, and `OTHER_NODE_ENV`) to the `.env.sample` file, along with their descriptions in the README.
- Added the `HIGHCHARTS_CACHE_PATH` option available through `.env` to set a custom directory for the fetched files.
- Added several new functions to the `highcharts-export-server` module, including `logWithStack`, `setLogLevel`, `enableFileLogging`, `manualConfig`, `printLogo`, and `printUsage`.
- Added a new `initLogging` function where the `setLogLevel` and `enableFileLogging` logic are consolidated into one place.
- Added a new utility function, `isObjectEmpty`.
- Added a new logging level (`5`) for benchmarking logs.
- Added legacy names of options to the `defaultConfig` and `mapToNewConfig` function in order to support the old, PhantomJS-based structure of options.
- Reordered the `error` and `info` arguments in the callback of the `startExport` function.
- Renamed the `HIGHCHARTS_MODULES` and `HIGHCHARTS_INDICATORS` environment variables respectively to `HIGHCHARTS_MODULE_SCRIPTS` and `HIGHCHARTS_INDICATOR_SCRIPTS`.
- Renamed the `scripts` property of the config options to `customScripts`.
- Renamed the `initPool` function to `initExport` in the main module.
- Renamed the `init` function to `initPool` in the pool module.
- Replaced the temporary benchmark module with a simpler server benchmark for evaluating export time.
Expand Down
54 changes: 28 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ There are four main ways of loading configurations:

The JSON below represents the default configuration stored in the `lib/schemas/config.js` file. If no `.env` file is found (more details on the file and environment variables below), these options will be used.

The format, along with its default values, is as follows (using the recommended ordering of core scripts and modules below):
The format, along with its default values, is as follows (using the recommended ordering of core and module scripts below):

```
{
Expand All @@ -102,7 +102,7 @@ The format, along with its default values, is as follows (using the recommended
"highcharts-more",
"highcharts-3d"
],
"modules": [
"moduleScripts": [
"stock",
"map",
"gantt",
Expand Down Expand Up @@ -167,10 +167,10 @@ The format, along with its default values, is as follows (using the recommended
"heikinashi",
"flowmap"
],
"indicators": [
"indicatorScripts": [
"indicators-all"
],
"scripts": [
"customScripts": [
"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.34/moment-timezone-with-data.min.js"
],
Expand Down Expand Up @@ -206,11 +206,10 @@ The format, along with its default values, is as follows (using the recommended
"host": "0.0.0.0",
"port": 7801,
"benchmarking": false,
"ssl": {
"enable": false,
"force": false,
"port": 443,
"certPath": ""
"proxy": {
"host": "",
"port": 8080,
"timeout": 5000
},
"rateLimiting": {
"enable": false,
Expand All @@ -220,6 +219,12 @@ The format, along with its default values, is as follows (using the recommended
"trustProxy": false,
"skipKey": "",
"skipToken": ""
},
"ssl": {
"enable": false,
"force": false,
"port": 443,
"certPath": ""
}
},
"pool": {
Expand Down Expand Up @@ -258,17 +263,13 @@ To load an additional JSON configuration file, use the `--loadConfig <filepath>`

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.

### Node Environment Config

- `NODE_ENV`: The type of Node.js environment. The value controls whether to include the error's stack in a response or not. Can be development or production (defaults to `development`).

### Highcharts Config

- `HIGHCHARTS_VERSION`: Highcharts version to use (defaults to `latest`).
- `HIGHCHARTS_CDN_URL`: Highcharts CDN URL of scripts to be used (defaults to `https://code.highcharts.com/`).
- `HIGHCHARTS_CORE_SCRIPTS`: Highcharts core scripts to fetch (defaults to ``).
- `HIGHCHARTS_MODULES`: Highcharts modules to fetch (defaults to ``).
- `HIGHCHARTS_INDICATORS`: Highcharts indicators to fetch (defaults to ``).
- `HIGHCHARTS_MODULE_SCRIPTS`: Highcharts module scripts to fetch (defaults to ``).
- `HIGHCHARTS_INDICATOR_SCRIPTS`: Highcharts indicator scripts to fetch (defaults to ``).
- `HIGHCHARTS_FORCE_FETCH`: The flag that determines whether to refetch all scripts after each server rerun (defaults to `false`).
- `HIGHCHARTS_CACHE_PATH`: In which directory should the fetched Highcharts scripts be placed (defaults to `.cache`).
- `HIGHCHARTS_ADMIN_TOKEN`: An authentication token that is required to switch the Highcharts version on the server at runtime (defaults to ``).
Expand All @@ -294,12 +295,11 @@ These variables are set in your environment and take precedence over options fro
- `SERVER_PORT`: The port to be used for the server when enabled (defaults to `7801`).
- `SERVER_BENCHMARKING`: Indicates whether to display a message with the duration, in milliseconds, of specific actions that occur on the server while serving a request (defaults to `false`).

### Server SSL Config
### Server Proxy Config

- `SERVER_SSL_ENABLE`: Enables or disables the SSL protocol (defaults to `false`).
- `SERVER_SSL_FORCE`: If set to true, the server is forced to serve only over HTTPS (defaults to `false`).
- `SERVER_SSL_PORT`: The port on which to run the SSL server (defaults to `443`).
- `SERVER_SSL_CERT_PATH`: The path to the SSL certificate/key file (defaults to ``).
- `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_TIMEOUT`: The timeout for the proxy server to use, if it exists (defaults to ``).

### Server Rate Limiting Config

Expand All @@ -311,6 +311,13 @@ These variables are set in your environment and take precedence over options fro
- `SERVER_RATE_LIMITING_SKIP_KEY`: Allows bypassing the rate limiter and should be provided with the _skipToken_ argument (defaults to ``).
- `SERVER_RATE_LIMITING_SKIP_TOKEN`: Allows bypassing the rate limiter and should be provided with the _skipKey_ argument (defaults to ``).

### Server SSL Config

- `SERVER_SSL_ENABLE`: Enables or disables the SSL protocol (defaults to `false`).
- `SERVER_SSL_FORCE`: If set to true, the server is forced to serve only over HTTPS (defaults to `false`).
- `SERVER_SSL_PORT`: The port on which to run the SSL server (defaults to `443`).
- `SERVER_SSL_CERT_PATH`: The path to the SSL certificate/key file (defaults to ``).

### Pool Config

- `POOL_MIN_WORKERS`: The number of minimum and initial pool workers to spawn (defaults to `4`).
Expand Down Expand Up @@ -338,14 +345,9 @@ These variables are set in your environment and take precedence over options fro

### Other Config

- `OTHER_NODE_ENV`: The type of Node.js environment. The value controls whether to include the error's stack in a response or not. Can be development or production (defaults to `production`).
- `OTHER_NO_LOGO`: Skip printing the logo on a startup. Will be replaced by a simple text (defaults to `false`).

### Proxy Config

- `PROXY_SERVER_HOST`: The host of the proxy server to use, if it exists (defaults to ``).
- `PROXY_SERVER_PORT`: The port of the proxy server to use, if it exists (defaults to ``).
- `PROXY_SERVER_TIMEOUT`: The timeout for the proxy server to use, if it exists (defaults to ``).

## Command Line Arguments

To supply command line arguments, add them as flags when running the application:
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.

Loading
Loading