-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·35 lines (24 loc) · 824 Bytes
/
index.js
File metadata and controls
executable file
·35 lines (24 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env node
var fs = require('fs');
var express = require('express');
var bodyParser = require('body-parser');
var anychart_nodejs = require('anychart-nodejs');
var indexTemplate = fs.readFileSync('./template.html', 'utf-8');
var app = express();
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.get('/', function (req, res) {
res.send(indexTemplate)
});
app.post('/export', function (req, res) {
anychart_nodejs.exportTo(req.body.code, 'png', function(err, data) {
var base64Data = data.toString('base64');
var result = {data: base64Data};
res.send(JSON.stringify(result));
});
});
app.listen(3000, function () {
console.log('Export server listening on port 3000!')
});