-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (32 loc) · 1.08 KB
/
server.js
File metadata and controls
39 lines (32 loc) · 1.08 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
const express = require('express');
const app = express();
const path = require('path');
var port = 3000;
let {PythonShell} = require('python-shell');
app.use(express.static(path.join(__dirname)));
app.listen(port, function () {
console.log(`server running on port ${port}`);
})
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
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.sendFile(path.join(__dirname + '/nofile.html'));
}
else {
let options = { args : [fileStructure],
pythonPath: environment};
if(keywords) {
options.args = options.args.concat([keywords]);
}
PythonShell.run('./DirectoryToGraph.py', options, function(err, data) {
if(err) res.send(err);
else res.sendFile(path.join(__dirname + '/success.html'));
});
}
}