hprasath commited on
Commit
e7e6e29
·
verified ·
1 Parent(s): 2b449de

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +26 -0
index.js CHANGED
@@ -15,6 +15,32 @@ app.get("/", function (req, res) {
15
  res.send("Hello World!!");
16
  });
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  app.post("/compile", function (req, res) {
19
  var code = req.body.code;
20
  var input = req.body.input;
 
15
  res.send("Hello World!!");
16
  });
17
 
18
+ app.post('/compile-java', (req, res) => {
19
+ const javaCode = req.body.code; // Assuming code is sent as a POST parameter
20
+
21
+ // Write the Java code to Main.java file
22
+ fs.writeFile('/code/temp/Main.java', javaCode, (err) => {
23
+ if (err) {
24
+ console.error(err);
25
+ res.status(500).send('Error writing Java file');
26
+ return;
27
+ }
28
+
29
+ // Compile and run the Java code
30
+ exec('javac -d /code/temp /code/temp/Main.java && java -cp /code/temp Main', (error, stdout, stderr) => {
31
+ if (error) {
32
+ console.error(error);
33
+ res.status(500).send('Error compiling or executing Java code');
34
+ return;
35
+ }
36
+
37
+ console.log(stdout);
38
+ console.error(stderr);
39
+ res.send(stdout);
40
+ });
41
+ });
42
+ });
43
+
44
  app.post("/compile", function (req, res) {
45
  var code = req.body.code;
46
  var input = req.body.input;