-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
78 lines (65 loc) · 1.91 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
67
68
69
70
71
72
73
74
75
76
77
78
const http = require("http");
const url = require('url');
const { exec } = require('child_process');
const host = 'localhost';
const port = 8002;
const requestListener = function (req, res) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Content-Type", "application/json");
const _url = url.parse(req.url, true);
const msg = _url.query;
switch (_url.pathname) {
case "/trs":
console.log(msg['rules']);
exec(__dirname + `/haskell/provskell-exe 0 ${msg['rules']}`, (error, stdout, stderr) => {
if (error) {
console.error(`error: ${error.message}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
res.writeHead(200);
res.end(stdout);
console.log(`stdout:\n${stdout}`);
});
break
case "/prove":
console.log(msg);
exec(__dirname + `/haskell/provskell-exe 1 ${msg['rules']} ${msg['funcs']} ${msg['n']}`, (error, stdout, stderr) => {
if (error) {
console.error(`error: ${error.message}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
res.writeHead(200);
res.end(stdout);
console.log(`stdout:\n${stdout}`);
});
break
case "/calc":
console.log(msg);
exec(__dirname + `/haskell/provskell-exe 2 ${msg['expr']}`, (error, stdout, stderr) => {
if (error) {
console.error(`error: ${error.message}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
res.writeHead(200);
res.end(stdout);
console.log(`stdout:\n${stdout}`);
});
break
}
}
const server = http.createServer(requestListener);
server.listen(port, host, () => {
console.log(`Server is running on http://${host}:${port}`);
});