highcharts-export-server
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "highcharts-export-server", | ||
"version": "0.1.0" | ||
"author": "Highsoft AS <support@highcharts.com> (http://www.highcharts.com/about)", | ||
"repository": { | ||
"url": "https://github.com/highcharts/node-export-server", | ||
"type": "git" | ||
}, | ||
"version": "0.1.1", | ||
"bin": { | ||
"highcharts-export-server": "./bin/cli.js" | ||
}, | ||
"scripts": { | ||
"install": "node ./build.js" | ||
}, | ||
"main": "lib/index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"express-rate-limit": "*", | ||
"mkdirp": "*", | ||
"colors": "*", | ||
"express": "*", | ||
"phantomjs-prebuilt": "*", | ||
"body-parser": "*", | ||
"prompt": "*", | ||
"request": "*", | ||
"express-form-data": "*", | ||
"cors": "*", | ||
"node-uuid": "*" | ||
} | ||
} | ||
222
README.md
@@ -1,1 +0,221 @@ | ||
# highcharts-export-server | ||
# Highcharts Node.js Export Server | ||
The export server can be ran as both a CLI converter, and as a HTTP server. | ||
## Install | ||
npm install highcharts-export-server -g | ||
OR: | ||
git clone https://github.com/highcharts/node-export-server | ||
npm install | ||
npm link | ||
## Running | ||
highcharts-export-server <arguments> | ||
## Command Line Arguments | ||
* `--infile`: Specify the input file. | ||
* `--instr`: Specify the input as a string. | ||
* `--options`: Alias for `--instr` | ||
* `--outfile`: Specify the output filename. | ||
* `--type`: The type of the exported file. Valid options are `jpg png pdf svg`. | ||
* `--scale`: The scale of the chart. | ||
* `--width`: Scale the chart to fit the width supplied - overrides `--scale`. | ||
* `--constr`: The constructor to use. Either `Chart` or `StockChart`. | ||
* `--callback`: File containing JavaScript to call in the constructor of Highcharts. | ||
* `--resources`: Stringified JSON. | ||
* `--host`: The hostname to run a server on. | ||
* `--port`: The port to listen for incoming requests on. | ||
* `--tmpdir`: The path to temporary output files. | ||
* `--sslPath`: The path to the SSL key/certificate. Indirectly enables SSL support. | ||
* `--enableServer <1|0>`: Enable the server (done also when supplying --host) | ||
* `--logDest <path>`: Set path for log files, and enable file logging | ||
* `--logLevel <0..4>`: Set the log level. 0 = off, 1 = errors, 2 = warn, 3 = notice, 4 = verbose | ||
* `--batch "input.json=output.png;input2.json=output2.png;.."`: Batch convert | ||
`-` and `--` can be used interchangeably when using the CLI. | ||
## Setup: Injecting the Highcharts dependency | ||
In order to use the export server, Highcharts.js needs to be injected | ||
into the export template. | ||
This is largely an automatic process. When running `npm install` you will | ||
be prompted to accept the license terms of Highcharts.js. Answering `yes` will | ||
pull the latest source from the Highcharts CDN and put them where they need to be. | ||
However, if you need to do this manually you can run `node build.js`. | ||
## HTTP Server | ||
The server accepts the following arguments: | ||
* `infile`: A string containing JSON or SVG for the chart | ||
* `options`: Aliast for `infile` | ||
* `svg`: A string containing SVG to render | ||
* `type`: The format: `png`, `jpeg`, `pdf`, `svg`. Mimetypes can also be used. | ||
* `scale`: The scale factor | ||
* `width`: The chart width (overrides scale) | ||
* `callback`: Javascript to execute in the highcharts constructor. | ||
* `resources`: Additional resources. | ||
* `constr`: The constructor to use. Either `Chart` or `Stock`. | ||
* `b64`: Bool, set to true to get base64 back instead of binary. | ||
* `async`: Get a download link instead of the file data | ||
* `noDownload`: Bool, set to true to not send attachment headers on the response. | ||
* `asyncRendering`: Wait for the included scripts to call `highexp.done()` before rendering the chart. | ||
Note that the `b64` option overrides the `async` option. | ||
It responds to `application/json`, `multipart/form-data`, and URL encoded requests. | ||
CORS is enabled for the server. | ||
It's recommended to run the server using [forever](https://github.com/foreverjs/forever). | ||
### SSL | ||
To enable ssl support, drop your `server.key` and `server.crt` in the ssl folder, | ||
or add `--sslPath <path to key/crt>` when running the server. | ||
## Server Test | ||
Run the below in a terminal after running `highcharts-export-server --enableServer`. | ||
# Generate a chart and save it to mychart.png | ||
curl -H "Content-Type: application/json" -X POST -d '{"infile":{"title": {"text": "Steep Chart"}, "xAxis": {"categories": ["Jan", "Feb", "Mar"]}, "series": [{"data": [29.9, 71.5, 106.4]}]}}' 127.0.0.1:7801 -o mychart.png | ||
## Using as a Node.js Module | ||
The export server can also be used as a node module to simplify integrations: | ||
//Include the exporter module | ||
const exporter = require('highcharts-export-server'); | ||
//Export settings | ||
var exportSettings = { | ||
type: 'png', | ||
options: { | ||
title: { | ||
text: 'My Chart' | ||
}, | ||
xAxis: { | ||
categories: ["Jan", "Feb", "Mar", "Apr", "Mar", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] | ||
}, | ||
series: [ | ||
{ | ||
type: 'line', | ||
data: [1, 3, 2, 4] | ||
}, | ||
{ | ||
type: 'line', | ||
data: [5, 3, 4, 2] | ||
} | ||
] | ||
} | ||
}; | ||
//Set up a pool of PhantomJS workers | ||
exporter.initPool(); | ||
//Perform an export | ||
/* | ||
Export settings corresponds to the available CLI arguments described | ||
above. | ||
*/ | ||
exporter.export(exportSettings, function (err, res) { | ||
... | ||
//Kill the pool when we're done with it | ||
exporter.killPool(); | ||
}); | ||
### Node.js API Reference | ||
**highcharts-export-server module** | ||
**Functions** | ||
* `log(level, ...)`: log something. Level is a number from 1-4. Args are joined by whitespace to form the message. | ||
* `logLevel(level)`: set the current log level: `0`: disabled, `1`: errors, `2`: warnings, `3`: notices, `4`: verbose | ||
* `enableFileLogging(path, name)`: enable logging to file. `path` is the path to log to, `name` is the filename to log to | ||
* `export(exportOptions, fn)`: do an export. `exportOptions` uses the same attribute names as the CLI switch names. `fn` is called when the export is completed, with an object as the second argument containing the the filename attribute. | ||
* `startServer(port, sslPort, sslPath)`: start an http server on the given port. `sslPath` is the path to the server key/certificate (must be named server.key/server.crt) | ||
* `server` - the server instance | ||
* `enableRateLimiting(options)` - enable rate limiting on the POST path | ||
* `max` - the maximum amount of requests before rate limiting kicks in | ||
* `window` - the time window in minutes for rate limiting. Example: setting `window` to `1` and `max` to `30` will allow a maximum of 30 requests within one minute. | ||
* `delay` - the amount to delay each successive request before hitting the max | ||
* `trustProxy` - set this to true if behind a load balancer | ||
* `app()` - returns the express app | ||
* `express()` - return the express module instance | ||
* `useFilter(when, fn)` - attach a filter to the POST route. Returning false in the callback will terminate the request. | ||
* `when` - either `beforeRequest` or `afterRequest` | ||
* `fn` - the function to call | ||
* `req` - the request object | ||
* `res` - the result object | ||
* `data` - the request data | ||
* `id` - the request ID | ||
* `uniqueid` - the unique id for the request (used for temporary file names) | ||
* `initPool(config)`: init the phantom pool - must be done prior to exporting. `config` is an object as such: | ||
* `maxWorkers` (default 25) - max count of worker processes | ||
* `initialWorkers` (default 5) - initial worker process count | ||
* `workLimit` (default 50) - how many task can be performed by a worker process before it's automatically restarted | ||
* `killPool()`: kill the phantom processes | ||
## Using Ajax in Injected Resources | ||
If you need to perform Ajax requests inside one of the resource scripts, | ||
set `asyncRendering` to true, and call `highexp.done()` in the Ajax return to process the chart. | ||
Example: | ||
{ | ||
asyncRendering: true, | ||
resources: { | ||
files: 'myAjaxScript.js' | ||
} | ||
} | ||
myAjaxScript.js: | ||
jQuery.ajax({ | ||
url: 'example.com', | ||
success: function (data) { | ||
... | ||
highexp.done(); | ||
}, | ||
error: function () { | ||
highexp.done(); | ||
} | ||
}); | ||
If the Ajax call doesn't call `highexp.done()` within 60 seconds, the | ||
rendering will time out. | ||
## Performance Notice | ||
In cases of batch exports, it's faster to use the HTTP server than the CLI. | ||
This is due to the overhead of starting PhantomJS for each job when using the CLI. | ||
As a concrete example, running the CLI with [testcharts/basic.json](testcharts/basic.json) | ||
as the input and converting to PNG averages about 449ms. | ||
Posting the same configuration to the HTTP server averages less than 100ms. | ||
So it's better to write a bash script that starts the server and then | ||
performs a set of POSTS to it through e.g. curl if not wanting to host the | ||
export server as a service. | ||
Alternatively, you can use the `--batch` switch if the output format is the same | ||
for each of the input files to process: | ||
highcharts-export-server --batch "infile1.json=outfile1.png;infile2.json=outfile2.png;.." | ||
Other switches can be combined with this switch. | ||
## License | ||
[MIT](LICENSE). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 11 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
1
2
221
104745
11
28
1573
11
1
10
4
+ Addedbody-parser@*
+ Addedcolors@*
+ Addedcors@*
+ Addedexpress@*
+ Addedexpress-form-data@*
+ Addedexpress-rate-limit@*
+ Addedmkdirp@*
+ Addednode-uuid@*
+ Addedphantomjs-prebuilt@*
+ Addedprompt@*
+ Addedrequest@*
+ Added@colors/colors@1.5.0(transitive)
+ Addedaccepts@2.0.0(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedarray-flatten@3.0.0(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasync@2.6.43.2.3(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedat-least-node@1.0.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbody-parser@2.0.2(transitive)
+ Addedbuffer-crc32@0.2.13(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcolors@1.0.31.4.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedconnect-multiparty@2.2.0(transitive)
+ Addedcontent-disposition@1.0.0(transitive)
+ Addedcontent-type@1.0.5(transitive)
+ Addedcookie@0.7.1(transitive)
+ Addedcookie-signature@1.2.2(transitive)
+ Addedcore-util-is@1.0.21.0.3(transitive)
+ Addedcors@2.8.5(transitive)
+ Addedcycle@1.0.3(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddebug@2.6.93.1.04.3.64.3.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddepd@1.1.22.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedencodeurl@1.0.22.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes6-promise@4.2.8(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedetag@1.8.1(transitive)
+ Addedexpress@5.0.1(transitive)
+ Addedexpress-form-data@2.0.23(transitive)
+ Addedexpress-rate-limit@7.4.1(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextract-zip@1.7.0(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedeyes@0.1.8(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfd-slicer@1.1.0(transitive)
+ Addedfinalhandler@2.0.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedforwarded@0.2.0(transitive)
+ Addedfresh@0.5.22.0.0(transitive)
+ Addedfs-extra@1.0.09.1.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasha@2.2.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-errors@1.7.31.8.12.0.0(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addediconv-lite@0.5.20.6.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedipaddr.js@1.9.1(transitive)
+ Addedis-promise@4.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsonfile@2.4.06.1.0(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedkew@0.7.0(transitive)
+ Addedklaw@1.3.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmedia-typer@0.3.01.1.0(transitive)
+ Addedmerge-descriptors@2.0.0(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime-db@1.52.01.53.0(transitive)
+ Addedmime-types@2.1.353.0.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.63.0.1(transitive)
+ Addedms@2.0.02.1.22.1.3(transitive)
+ Addedmultiparty@4.2.3(transitive)
+ Addedmute-stream@0.0.8(transitive)
+ Addednegotiator@1.0.0(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedon-finished@2.3.02.4.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedpath-to-regexp@8.2.0(transitive)
+ Addedpend@1.2.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedphantomjs-prebuilt@2.1.16(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedprogress@1.1.8(transitive)
+ Addedprompt@1.3.0(transitive)
+ Addedproxy-addr@2.0.7(transitive)
+ Addedpsl@1.10.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.13.06.5.3(transitive)
+ Addedrandom-bytes@1.0.0(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedraw-body@3.0.0(transitive)
+ Addedread@1.0.7(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedrequest-progress@2.0.1(transitive)
+ Addedrevalidator@0.1.8(transitive)
+ Addedrouter@2.0.0(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsend@1.1.0(transitive)
+ Addedserve-static@2.1.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsetprototypeof@1.1.11.2.0(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstack-trace@0.0.10(transitive)
+ Addedstatuses@1.5.02.0.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedthrottleit@1.0.1(transitive)
+ Addedtoidentifier@1.0.01.0.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtype-is@1.6.182.0.0(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addeduid-safe@2.1.5(transitive)
+ Addeduniversalify@2.0.1(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedutils-merge@1.0.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedvary@1.1.2(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwinston@2.4.7(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyauzl@2.10.0(transitive)