wudysoft commited on
Commit
d7051a7
·
verified ·
1 Parent(s): 34a0297

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +26 -0
app.js CHANGED
@@ -8,6 +8,7 @@ import fetch from 'node-fetch';
8
  import sharp from 'sharp';
9
  import { spawn } from 'child_process';
10
  import path from 'path';
 
11
 
12
  import EventEmitter from 'events';
13
  import WebSocket from 'ws';
@@ -2142,6 +2143,31 @@ app.get('/ask', async (req, res) => {
2142
  }
2143
  });
2144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2145
  const PORT = process.env.PORT || 7860;
2146
 
2147
  app.listen(PORT, async () => {
 
8
  import sharp from 'sharp';
9
  import { spawn } from 'child_process';
10
  import path from 'path';
11
+ import { NodeVM } from "vm2";
12
 
13
  import EventEmitter from 'events';
14
  import WebSocket from 'ws';
 
2143
  }
2144
  });
2145
 
2146
+ app.post("/playwright", async (req, res) => {
2147
+ const { code } = req.body;
2148
+
2149
+ if (!code) {
2150
+ return res.status(400).json({ output: "code is required" });
2151
+ }
2152
+
2153
+ try {
2154
+ const vm = new NodeVM({
2155
+ sandbox: {},
2156
+ require: {
2157
+ external: ["playwright"],
2158
+ builtin: [],
2159
+ },
2160
+ });
2161
+
2162
+ const wrappedScript = `${code}`;
2163
+
2164
+ const output = await vm.run(wrappedScript, import.meta.url);
2165
+ res.json({ output });
2166
+ } catch (error) {
2167
+ res.status(500).json({ output: error.message });
2168
+ }
2169
+ });
2170
+
2171
  const PORT = process.env.PORT || 7860;
2172
 
2173
  app.listen(PORT, async () => {