Skip to content

Commit

Permalink
added fix for js exec
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhavsaxena committed Jun 25, 2023
1 parent 6b90d6d commit 7742aad
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const languages = [
name: "Java",
type: "java",
snippet:
'public class main {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println("Hello World!");\n\t}\n}',
'public class main {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println("Hello World!");\n\t}\n}\n',
},
];

Expand Down
3 changes: 2 additions & 1 deletion app/src/screens/IDE.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const IDE = () => {
setResponse(res.data.op);
setLoading(false);
} catch (err) {
toast.error("Something went wrong!", {
toast.error(`${err}`, {
position: toast.POSITION.TOP_RIGHT,
autoClose: 2000,
});
Expand All @@ -42,6 +42,7 @@ const IDE = () => {
};

const handlekeys = (e) => {
e.preventDefault();
if (e.shiftKey && e.keyCode === 13) {
fetch();
}
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ app.use(express.json());
app.use("/api/submit", submitCodeRoutes);

app.get("/", (req, res) => {
res.send("Server healthy");
res.send("Server alive");
});

app.listen(PORT, () => {
console.log(`Live @${PORT}`);
console.log(`Living @${PORT}`);
});
2 changes: 1 addition & 1 deletion operations/files/main.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log('Hello World!');
console.log('Hel World!');
12 changes: 3 additions & 9 deletions operations/interpreters/js.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { spawn } from "child_process";
import fs from "fs";
import { execFileSync } from "child_process";

const interpretjs = (code, input) => {
var output;
try {
fs.writeFileSync("./operations/files/main.js", code);
} catch (err) {
return err.toString();
}
try {
output = spawn("node", ["./operations/files/main.js"], {
output = execFileSync("node", ["-e", code], {
input: input,
timeout: 5000,
encoding: "utf-8",
});
}).toString();
} catch (err) {
return err.toString();
}
Expand Down

1 comment on commit 7742aad

@vercel
Copy link

@vercel vercel bot commented on 7742aad Jun 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

open-ide – ./

open-ide-git-main-sambhavsaxena.vercel.app
open-ide-sambhavsaxena.vercel.app
openide.vercel.app

Please sign in to comment.