-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (37 loc) · 985 Bytes
/
index.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
const express = require("express"),
app = express(),
port = process.env.PORT || 6942,
{ exec } = require("child_process")
app.set("view engine", "pug")
app.use("/", express.static("public"))
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.get("/", (req, res) => {
res.render("index")
})
app.post("/play", (req, res) => {
if (req.body.text) {
exec("python3 ./main.py " + (req.body.text.replace(/[\\$'"]/g, "\\$&")), (err, stdout, stderr) => {
if (err) {
console.log(err)
res.json({
error: err
})
}
else {
console.log(stdout)
res.json({
status: "success"
})
}
})
}
else {
res.json({
error: "No text provided"
})
}
})
app.listen(port, () => {
console.log(`Server running on port ${port}`)
})