-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
45 lines (42 loc) · 1.09 KB
/
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
43
44
45
const express = require("express");
const cors = require("cors");
const { execNode, execPython, execCpp } = require("./utils/executor");
const app = express();
const PORT = process.env.PORT || 3001;
app.use(express.json());
app.use(cors());
app.use(
express.urlencoded({
extended: true,
})
);
app.get("/", (req, res) => {
res.send("First server!!");
});
app.post("/execNode", async (req, res) => {
const data = req.body.code;
const input = req.body.input;
// console.log(data);
const output = await execNode(data, input || "");
console.log(output);
res.send(output);
});
app.post("/execPython", async (req, res) => {
const data = req.body.code;
const input = req.body.input;
// console.log(data);
const output = await execPython(data, input || "");
console.log(output);
res.send(output);
});
app.post("/execCpp", async (req, res) => {
const data = req.body.code;
const input = req.body.input;
// console.log(data);
const output = await execCpp(data, input ||"");
console.log(output);
res.send(output);
});
app.listen(PORT, () => {
console.log("Server started!!");
});