-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (39 loc) · 1.2 KB
/
server.js
File metadata and controls
48 lines (39 loc) · 1.2 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
46
const express = require('express');
const app = express();
const path = require('path');
var cors = require('cors');
var port = 3000;
let {PythonShell} = require('python-shell');
app.use(express.static(path.join(__dirname)));
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
next();
});
app.listen(port, function () {
console.log(`server running on port ${port}`);
});
app.post('/submit', executeData);
function executeData(req, res) {
var fileStructure = req.query.fileStructure;
var environment = req.query.environment;
var keywords = req.query.keywords;
if(!fileStructure || !environment) {
res.send('fail');
}
else {
let options = { args : [fileStructure],
pythonPath: environment};
if(keywords) {
options.args = options.args.concat([keywords]);
}
var child = PythonShell.run('./DirectoryToGraph.py', options, function(err, data) {
if(err) res.send('post request failed');
else {
res.send('success');
}
});
child.on('error', function(err) {
res.send('post request failed');
});
}
}