hprasath commited on
Commit
967b852
1 Parent(s): 6eb59c6

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +3 -1
index.js CHANGED
@@ -16,6 +16,7 @@ app.get("/", function (req, res) {
16
  res.send("Hello World!!");
17
  });
18
 
 
19
 
20
  app.post("/compile", function (req, res) {
21
  var code = req.body.code;
@@ -52,10 +53,11 @@ app.post("/compile", function (req, res) {
52
  }
53
  const javaProcess = exec(
54
  "javac -d /code/temp /code/temp/Main.java && java -cp /code/temp Main",
 
55
  (error, stdout, stderr) => {
56
  if (error) {
57
  console.error(error);
58
- res.send({error:stderr});
59
  return;
60
  }
61
  console.log(stdout);
 
16
  res.send("Hello World!!");
17
  });
18
 
19
+ const TIMEOUT_VALUE = 10000;
20
 
21
  app.post("/compile", function (req, res) {
22
  var code = req.body.code;
 
53
  }
54
  const javaProcess = exec(
55
  "javac -d /code/temp /code/temp/Main.java && java -cp /code/temp Main",
56
+ { timeout: TIMEOUT_VALUE }, // Add timeout option
57
  (error, stdout, stderr) => {
58
  if (error) {
59
  console.error(error);
60
+ res.send({error: "Compilation or execution timed out"});
61
  return;
62
  }
63
  console.log(stdout);