hprasath commited on
Commit
3a85ef1
1 Parent(s): f2e4670

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +68 -9
index.js CHANGED
@@ -29,19 +29,78 @@ app.post("/compile", function (req, res) {
29
 
30
  try {
31
  if (lang == "Cpp") {
32
- // Your existing code for compiling C++
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  } else if (lang == "Java") {
34
- // Your existing code for compiling Java
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  } else if (lang == "Python") {
36
- // Your existing code for compiling Python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
38
  } catch (e) {
39
  console.log("error:" + e);
40
  }
41
  });
42
-
43
- // Start the server
44
- const PORT = process.env.PORT || 7860;
45
- app.listen(PORT, () => {
46
- console.log(`Server is running on port ${PORT}`);
47
- });
 
29
 
30
  try {
31
  if (lang == "Cpp") {
32
+ if (!input) {
33
+ var envData = {
34
+ OS: "windows",
35
+ cmd: "g++",
36
+ options: { timeout: 10000 },
37
+ };
38
+ compiler.compileCPP(envData, code, function (data) {
39
+ if (data.output) {
40
+ res.send(data);
41
+ } else {
42
+ res.send({ error: data.error });
43
+ }
44
+ });
45
+ } else {
46
+ var envData = {
47
+ OS: "windows",
48
+ cmd: "g++",
49
+ options: { timeout: 10000 },
50
+ };
51
+ compiler.compileCPPWithInput(envData, code, input, function (data) {
52
+ if (data.output) {
53
+ res.send(data);
54
+ } else {
55
+ res.send({ error: data.error });
56
+ }
57
+ });
58
+ }
59
  } else if (lang == "Java") {
60
+ if (!input) {
61
+ var envData = { OS: "windows" };
62
+ compiler.compileJava(envData, code, function (data) {
63
+ if (data.output) {
64
+ res.send(data);
65
+ } else {
66
+ res.send({ error: data.error });
67
+ }
68
+ });
69
+ } else {
70
+ var envData = { OS: "windows" };
71
+
72
+ compiler.compileJavaWithInput(envData, code, input, function (data) {
73
+ if (data.output) {
74
+ res.send(data);
75
+ } else {
76
+ res.send({ error: data.error });
77
+ }
78
+ });
79
+ }
80
  } else if (lang == "Python") {
81
+ if (!input) {
82
+ var envData = { OS: "windows" };
83
+ compiler.compilePython(envData, code, function (data) {
84
+ if (data.output) {
85
+ res.send(data);
86
+ } else {
87
+ res.send({ error: data.error });
88
+ }
89
+ });
90
+ } else {
91
+ var envData = { OS: "windows" };
92
+ compiler.compilePythonWithInput(envData, code, input, function (data) {
93
+ if (data.output) {
94
+ res.send(data);
95
+ } else {
96
+ res.send({ error: data.error });
97
+ }
98
+ });
99
+ }
100
  }
101
  } catch (e) {
102
  console.log("error:" + e);
103
  }
104
  });
105
+ const port = 7860
106
+ app.listen(port, () => { console.log(`Open http://localhost:${port}`) })