Update app.js
Browse files
app.js
CHANGED
|
@@ -2157,8 +2157,9 @@ app.post("/playwright", async (req, res) => {
|
|
| 2157 |
if (!code) return res.status(400).json({ error: "Kode tidak boleh kosong" });
|
| 2158 |
|
| 2159 |
try {
|
|
|
|
| 2160 |
const vm = new NodeVM({
|
| 2161 |
-
console: "
|
| 2162 |
sandbox: {},
|
| 2163 |
require: {
|
| 2164 |
external: true,
|
|
@@ -2168,12 +2169,16 @@ app.post("/playwright", async (req, res) => {
|
|
| 2168 |
},
|
| 2169 |
});
|
| 2170 |
|
|
|
|
|
|
|
| 2171 |
const startIndex = expressLogs.length;
|
| 2172 |
const runCode = vm.run(`module.exports = async () => { ${code} };`, "sandbox.js");
|
| 2173 |
await runCode();
|
| 2174 |
-
|
|
|
|
|
|
|
| 2175 |
} catch (error) {
|
| 2176 |
-
res.status(500).json({ error: error.message, log: expressLogs.pop() || "" });
|
| 2177 |
}
|
| 2178 |
});
|
| 2179 |
|
|
|
|
| 2157 |
if (!code) return res.status(400).json({ error: "Kode tidak boleh kosong" });
|
| 2158 |
|
| 2159 |
try {
|
| 2160 |
+
let vmLogs = [];
|
| 2161 |
const vm = new NodeVM({
|
| 2162 |
+
console: "redirect",
|
| 2163 |
sandbox: {},
|
| 2164 |
require: {
|
| 2165 |
external: true,
|
|
|
|
| 2169 |
},
|
| 2170 |
});
|
| 2171 |
|
| 2172 |
+
vm.on("console.log", (msg) => vmLogs.push(msg));
|
| 2173 |
+
|
| 2174 |
const startIndex = expressLogs.length;
|
| 2175 |
const runCode = vm.run(`module.exports = async () => { ${code} };`, "sandbox.js");
|
| 2176 |
await runCode();
|
| 2177 |
+
|
| 2178 |
+
const logsAfterRun = [...expressLogs.slice(startIndex), ...vmLogs];
|
| 2179 |
+
res.json({ log: logsAfterRun.pop() || "" });
|
| 2180 |
} catch (error) {
|
| 2181 |
+
res.status(500).json({ error: error.message, log: [...expressLogs, ...vmLogs].pop() || "" });
|
| 2182 |
}
|
| 2183 |
});
|
| 2184 |
|