-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
65 lines (58 loc) · 2.56 KB
/
app.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
const express = require("express")
const bodyParser = require("body-parser")
const cors = require("cors")
const { exec } = require("child_process")
const fs = require("fs")
const app = express()
const port = 3000
app.use(cors())
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json({limit: "1000kb"}))
app.use("/js", express.static("static"))
app.post("/compile", (req, res) => {
const name = req.body.name
const sourceCode = req.body.sourceCode
const type = req.body.type
var msg = null
fs.writeFile("./static/" + name + ".cpp", sourceCode, err => {
if (err) {
msg = `stderr: ${err}`
console.error(msg)
return res.send({res: msg})
}
if (type == "indicator") {
exec('emcc ./static/' + name + '.cpp -o ./static/' + name + '.js -s EXTRA_EXPORTED_RUNTIME_METHODS=\'["ccall", "cwrap", "getValue", "setValue", "addFunction", "UTF8ToString", "lengthBytesUTF8", "stringToUTF8"]\' -s RESERVED_FUNCTION_POINTERS=200 -s MODULARIZE=1 -s \'EXPORT_NAME="IndiPlugIn"\' -s ENVIRONMENT=web -s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY -s \'ASYNCIFY_IMPORTS=["jVeriSig"]\' -O3', (error, stdout, stderr) => {
if (error) {
msg = `error: ${error.message}`
console.error(msg)
return res.send({res: msg})
}
if (stderr) {
msg = `${stderr}`
console.error(msg)
return res.send({res: msg})
}
msg = `${stdout}`
console.log(msg)
return res.send({res: msg})
})
} else {
exec('emcc ./static/' + name + '.cpp -o ./static/' + name + '.js -s EXTRA_EXPORTED_RUNTIME_METHODS=\'["ccall", "cwrap", "getValue", "setValue", "addFunction", "UTF8ToString", "lengthBytesUTF8", "stringToUTF8"]\' -s RESERVED_FUNCTION_POINTERS=200 -s MODULARIZE=1 -s \'EXPORT_NAME="EAPlugIn"\' -s ENVIRONMENT=web -s ASYNCIFY -s \'ASYNCIFY_IMPORTS=["jOrderSend", "jOrderModify", "jOrderClose", "jOrderDelete", "jVeriSig", "jBuildCNN", "jTrainCNN", "jRunCNN", "jSaveCNN", "jLoadCNN"]\' -O3 -s TOTAL_STACK=32MB -s INITIAL_MEMORY=64MB -s ALLOW_MEMORY_GROWTH=1', (error, stdout, stderr) => {
if (error) {
msg = `error: ${error.message}`
console.error(msg)
return res.send({res: msg})
}
if (stderr) {
msg = `${stderr}`
console.error(msg)
return res.send({res: msg})
}
msg = `${stdout}`
console.log(msg)
return res.send({res: msg})
})
}
})
})
app.listen(port, () => console.log(`Listening on port ${port}!`))