node.js - Issues Getting Highcharts Export Server Running Under iisnode -
i working on trying set highcharts export server under node.js using iisnode (https://github.com/tjanczuk/iisnode). acts pipe between requests iis through node. great! only, how "install" highcharts export server using iisnode? did instructions on how install highcharts-export node module installed under (windows) appdata\roaming\npm. how move or point iisnode export server? export server run via following once installed npm:
highcharts-export-server --enableserver 1
so, installed , used in iis8 + iisnode 1) right directory install export server locally (on windows modules pulled in via npm go c:\users\\appdata\roaming\nmp\ logged in user using npm install package)? 2) iisnode configuration necessary this?
i have iisnode setup , running on our development box , examples work. confusion lies partly utter lack of documentation issnode. links have found repeat items listed in links issnode developer no actual "here how take node app exists in npm , have work in issnode." don't need hand held every step of way. seeing no list of steps follow.
install node (if not installed)
install iisnode (if not installed => https://github.com/tjanczuk/iisnode)
verify iis has iisnode registered module
create new application pool, set "no managed code"
create new empty web site
load iisnode sample content it, update web.config
verify can hit , runs , can write it's logs
go iis web site folder , run these npm commands
npm init /empty
npm install --save highcharts-export-server
npm install --save tmp
add file hcexport.js , reconfigure web.config
var fs = require('fs'); var http = require('http'); var path = require("path"); var tmp = require('tmp'); const exporter = require('highcharts-export-server'); http.createserver(function (req, res) { try { if (req.method !== 'post') { throw "post only"; } var body = ''; req.on('data', function (data) { body += data; }); req.on('end', function () { if (body === '') { throw "empty body"; } var tempfile = tmp.filesync({discarddescriptor: true, postfix: ".svg", dir: process.cwd()}); var input = json.parse(body); input.outfile = path.basename(tempfile.name); exporter.initpool(); exporter.export(input, function (err, exres) { if (err) { throw "export failed"; } var filename = path.join(process.cwd(), exres.filename); exporter.killpool(); fs.readfile(filename, function(err, file) { res.writehead(200, { 'content-type': 'image/svg+xml', 'content-disposition': 'attachment; filename=' + exres.filename }); res.write(file.tostring()); res.end(); tempfile.removecallback(); }); }); }); } catch (err) { console.log({port: process.env.port, error: err}); res.writehead(409, { 'content-type': 'text/html' }); res.end(err.message); } }).listen(process.env.port);
extend needed support export types plan use.
the highcharts-export-server uses phantomjs internally , can run away under error conditions using 100% of available cpu, if see can kill using:
taskkill /im phantomjs.exe /f
Comments
Post a Comment