Update app.js
Browse files
app.js
CHANGED
|
@@ -2144,28 +2144,27 @@ app.get('/ask', async (req, res) => {
|
|
| 2144 |
});
|
| 2145 |
|
| 2146 |
app.post("/playwright", async (req, res) => {
|
| 2147 |
-
|
| 2148 |
-
if (!code) return res.status(400).json({ output: "code is required" });
|
| 2149 |
|
| 2150 |
-
|
| 2151 |
-
const logs = [];
|
| 2152 |
-
const originalConsoleLog = console.log;
|
| 2153 |
-
console.log = (...args) => {
|
| 2154 |
-
logs.push(args.map(arg => (typeof arg === "object" ? JSON.stringify(arg, null, 2) : String(arg))).join(" "));
|
| 2155 |
-
originalConsoleLog(...args);
|
| 2156 |
-
};
|
| 2157 |
|
| 2158 |
-
|
| 2159 |
-
|
| 2160 |
-
|
| 2161 |
-
|
|
|
|
|
|
|
| 2162 |
|
| 2163 |
-
|
| 2164 |
-
|
| 2165 |
-
|
| 2166 |
-
|
| 2167 |
-
|
| 2168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2169 |
});
|
| 2170 |
|
| 2171 |
const PORT = process.env.PORT || 7860;
|
|
|
|
| 2144 |
});
|
| 2145 |
|
| 2146 |
app.post("/playwright", async (req, res) => {
|
| 2147 |
+
const { code } = req.body;
|
|
|
|
| 2148 |
|
| 2149 |
+
if (!code) return res.status(400).json({ error: "Kode tidak boleh kosong" });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2150 |
|
| 2151 |
+
try {
|
| 2152 |
+
const vm = new VM({
|
| 2153 |
+
sandbox: {
|
| 2154 |
+
playwright: { chromium },
|
| 2155 |
+
},
|
| 2156 |
+
});
|
| 2157 |
|
| 2158 |
+
const result = await vm.run(`
|
| 2159 |
+
(async () => {
|
| 2160 |
+
${code}
|
| 2161 |
+
})();
|
| 2162 |
+
`);
|
| 2163 |
+
|
| 2164 |
+
res.json({ output: result });
|
| 2165 |
+
} catch (error) {
|
| 2166 |
+
res.status(500).json({ error: error.message });
|
| 2167 |
+
}
|
| 2168 |
});
|
| 2169 |
|
| 2170 |
const PORT = process.env.PORT || 7860;
|