-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
66 lines (54 loc) · 1.64 KB
/
server.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var express = require('express'),
app = express(),
swig = require('swig'),
people;
// This is where all the magic happens!
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/'));
// Swig will cache templates for you, but you can disable
// that and use Express's caching instead, if you like:
app.set('view cache', false);
// To disable Swig's cache, do the following:
swig.setDefaults({ cache: false });
// NOTE: You should always cache templates in a production environment.
// Don't leave both of these to `false` in production!
app.get('/', function (req, res) {
res.render('index.html', { /* template locals context */ });
});
app.get('/start', function (req, res) {
console.log(req.query.string);
fs = require('fs')
fs.writeFileSync('test_str.txt', req.query.string, 'utf8');
/*var execSync = require('exec-sync');
execSync('./a.out');*/
var FFI = require("node-ffi");
var libc = new FFI.Library(null, {
"system": ["int32", ["string"]]
});
var run = libc.system;
run("./a.out");
var data = fs.readFileSync('result.txt', 'utf8');
if(data.indexOf("YES") != -1)
{
//csv = fs.readFileSync('trace.csv', 'utf8');
var Converter = require('csvtojson').core.Converter;
var csvFileName = "trace.csv";
var csvConverter = new Converter();
csvConverter.on("end_parsed", function(jsonObj)
{
jsonObj["result"] = "YES";
res.send(jsonObj);
});
csvConverter.from(csvFileName);
}
else
{
var jsonObj = {};
jsonObj["result"] = "NO";
res.send(jsonObj);
}
});
app.listen(1337);
console.log('Application Started on http://localhost:1337/');