Update app.js
Browse files
app.js
CHANGED
|
@@ -2145,15 +2145,11 @@ app.get('/ask', async (req, res) => {
|
|
| 2145 |
}
|
| 2146 |
});
|
| 2147 |
|
| 2148 |
-
// Simpan log utama Express
|
| 2149 |
let expressLogs = [];
|
| 2150 |
-
|
| 2151 |
-
// Override console.log agar log disimpan di Express
|
| 2152 |
const originalLog = console.log;
|
| 2153 |
console.log = (...args) => {
|
| 2154 |
-
|
| 2155 |
-
|
| 2156 |
-
originalLog.apply(console, args); // Tetap tampilkan di terminal
|
| 2157 |
};
|
| 2158 |
|
| 2159 |
app.post("/playwright", async (req, res) => {
|
|
@@ -2162,7 +2158,7 @@ app.post("/playwright", async (req, res) => {
|
|
| 2162 |
|
| 2163 |
try {
|
| 2164 |
const vm = new NodeVM({
|
| 2165 |
-
console: "inherit",
|
| 2166 |
sandbox: {},
|
| 2167 |
require: {
|
| 2168 |
external: true,
|
|
@@ -2172,23 +2168,12 @@ app.post("/playwright", async (req, res) => {
|
|
| 2172 |
},
|
| 2173 |
});
|
| 2174 |
|
| 2175 |
-
const
|
| 2176 |
-
|
| 2177 |
-
console.log("Kode sedang berjalan di Express...");
|
| 2178 |
-
${code}
|
| 2179 |
-
};
|
| 2180 |
-
`;
|
| 2181 |
-
|
| 2182 |
-
const startIndex = expressLogs.length; // Simpan indeks log sebelum runCode()
|
| 2183 |
-
const runCode = vm.run(script, "sandbox.js");
|
| 2184 |
await runCode();
|
| 2185 |
-
|
| 2186 |
-
// Ambil log hanya setelah runCode()
|
| 2187 |
-
const logsAfterRun = expressLogs.slice(startIndex);
|
| 2188 |
-
|
| 2189 |
-
res.json({ logs: logsAfterRun });
|
| 2190 |
} catch (error) {
|
| 2191 |
-
res.status(500).json({ error: error.message,
|
| 2192 |
}
|
| 2193 |
});
|
| 2194 |
|
|
|
|
| 2145 |
}
|
| 2146 |
});
|
| 2147 |
|
|
|
|
| 2148 |
let expressLogs = [];
|
|
|
|
|
|
|
| 2149 |
const originalLog = console.log;
|
| 2150 |
console.log = (...args) => {
|
| 2151 |
+
expressLogs.push(args.map(arg => (typeof arg === "object" ? JSON.stringify(arg) : arg)).join(" "));
|
| 2152 |
+
originalLog.apply(console, args);
|
|
|
|
| 2153 |
};
|
| 2154 |
|
| 2155 |
app.post("/playwright", async (req, res) => {
|
|
|
|
| 2158 |
|
| 2159 |
try {
|
| 2160 |
const vm = new NodeVM({
|
| 2161 |
+
console: "inherit",
|
| 2162 |
sandbox: {},
|
| 2163 |
require: {
|
| 2164 |
external: true,
|
|
|
|
| 2168 |
},
|
| 2169 |
});
|
| 2170 |
|
| 2171 |
+
const startIndex = expressLogs.length;
|
| 2172 |
+
const runCode = vm.run(`module.exports = async () => { ${code} };`, "sandbox.js");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2173 |
await runCode();
|
| 2174 |
+
res.json({ log: expressLogs.slice(startIndex).pop() || "" });
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2175 |
} catch (error) {
|
| 2176 |
+
res.status(500).json({ error: error.message, log: expressLogs.pop() || "" });
|
| 2177 |
}
|
| 2178 |
});
|
| 2179 |
|