wudysoft commited on
Commit
5f5cd12
·
verified ·
1 Parent(s): 6a522dc

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +13 -6
app.js CHANGED
@@ -2157,9 +2157,11 @@ app.post("/playwright", async (req, res) => {
2157
  console.log("[INFO] Eksekusi kode dimulai...");
2158
  console.log("[CODE] ====>\n", code);
2159
 
 
 
2160
  try {
2161
  const vm = new NodeVM({
2162
- console: "inherit",
2163
  sandbox: {},
2164
  require: {
2165
  external: true,
@@ -2171,6 +2173,12 @@ app.post("/playwright", async (req, res) => {
2171
  },
2172
  });
2173
 
 
 
 
 
 
 
2174
  const script = `
2175
  module.exports = async () => {
2176
  console.log("[LOG] Eksekusi dimulai di dalam sandbox...");
@@ -2180,16 +2188,15 @@ app.post("/playwright", async (req, res) => {
2180
 
2181
  const runCode = vm.run(script, "sandbox.js");
2182
 
2183
- const result = await runCode();
2184
 
2185
- console.log("[INFO] Eksekusi berhasil!");
2186
- console.log("[RESULT] ====>", result);
2187
  console.log("====================================\n");
2188
 
2189
- res.json({ result });
2190
  } catch (error) {
2191
  console.error("[ERROR] Eksekusi gagal!", error);
2192
- res.status(500).json({ error: error.message });
2193
  }
2194
  });
2195
 
 
2157
  console.log("[INFO] Eksekusi kode dimulai...");
2158
  console.log("[CODE] ====>\n", code);
2159
 
2160
+ let logs = [];
2161
+
2162
  try {
2163
  const vm = new NodeVM({
2164
+ console: "redirect",
2165
  sandbox: {},
2166
  require: {
2167
  external: true,
 
2173
  },
2174
  });
2175
 
2176
+ // Tangkap log dari dalam VM
2177
+ vm.on("console.log", (msg) => {
2178
+ logs.push(msg);
2179
+ console.log("[SANDBOX]", msg);
2180
+ });
2181
+
2182
  const script = `
2183
  module.exports = async () => {
2184
  console.log("[LOG] Eksekusi dimulai di dalam sandbox...");
 
2188
 
2189
  const runCode = vm.run(script, "sandbox.js");
2190
 
2191
+ await runCode();
2192
 
2193
+ console.log("[INFO] Eksekusi selesai!");
 
2194
  console.log("====================================\n");
2195
 
2196
+ res.json({ logs });
2197
  } catch (error) {
2198
  console.error("[ERROR] Eksekusi gagal!", error);
2199
+ res.status(500).json({ error: error.message, logs });
2200
  }
2201
  });
2202