-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·45 lines (37 loc) · 1.05 KB
/
Copy pathserver.js
File metadata and controls
executable file
·45 lines (37 loc) · 1.05 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var path = require('path'),
childProcess = require('child_process'),
slimerjs = require('slimerjs'),
express = require('express'),
bodyParser = require('body-parser'),
app = express(),
binPath = slimerjs.path,
slimerPath = path.join(__dirname, 'slimer.js');
var fs = require('fs');
function execSlimer(url, callback) {
var filename = 'pics/' + new Date().getTime() + Math.round(Math.random()*10000) + '.png';
var childArgs = [
path.join(__dirname, 'slimer.js'),
url,
path.join(__dirname, 'public/' + filename)
];
childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
console.log(stdout);
callback(filename);
});
}
function getPic(req, res) {
console.log(req.body);
if(!req.body.url) {
res.end();
}
execSlimer(req.body.url, function(filename) {
var resBody = {'filename':filename};
res.json(resBody);
});
}
app.use(express.static('public'));
app.use(bodyParser.json());
app.post('/getPic', getPic);
var listenPort = process.env.PORT || 5000;
app.listen(listenPort);
console.log('Listening on port ' + listenPort);