Update app.mjs
Browse files
app.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { Hono } from 'hono'
|
|
| 4 |
import { logger } from 'hono/logger'
|
| 5 |
import { prettyJSON } from 'hono/pretty-json'
|
| 6 |
import os from 'node:os'
|
| 7 |
-
import
|
| 8 |
import { isMainThread, parentPort, Worker } from 'node:worker_threads'
|
| 9 |
import playwright from 'playwright-extra'
|
| 10 |
import prettyBytes from 'pretty-bytes'
|
|
@@ -21,7 +21,7 @@ if (!isMainThread) {
|
|
| 21 |
const fn = new AsyncFunction('playwright', 'pluginStealth', 'console', code)
|
| 22 |
parentPort.postMessage({ result: await fn(playwright, pluginStealth, console) })
|
| 23 |
} catch (error) {
|
| 24 |
-
parentPort.postMessage({ error:
|
| 25 |
}
|
| 26 |
})
|
| 27 |
}
|
|
@@ -84,7 +84,7 @@ const runBrowserScript = (code) =>
|
|
| 84 |
worker.postMessage(code)
|
| 85 |
worker.on('message', ({ result, error }) => {
|
| 86 |
cleanup()
|
| 87 |
-
error ? reject(new Error(error)) : resolve(
|
| 88 |
})
|
| 89 |
worker.on('error', (err) => {
|
| 90 |
cleanup()
|
|
@@ -99,7 +99,7 @@ const runBrowserScript = (code) =>
|
|
| 99 |
const app = new Hono()
|
| 100 |
|
| 101 |
app.use(logger())
|
| 102 |
-
app.use(prettyJSON())
|
| 103 |
app.use('/file/*', serveStatic({
|
| 104 |
root: os.tmpdir(),
|
| 105 |
rewriteRequestPath: (path) => path.replace(/^\/file/, '')
|
|
@@ -118,7 +118,7 @@ app.post('/run', async (c) => {
|
|
| 118 |
try {
|
| 119 |
return c.json({ result: await runBrowserScript(code) })
|
| 120 |
} catch (e) {
|
| 121 |
-
return c.json({ error:
|
| 122 |
}
|
| 123 |
})
|
| 124 |
|
|
|
|
| 4 |
import { logger } from 'hono/logger'
|
| 5 |
import { prettyJSON } from 'hono/pretty-json'
|
| 6 |
import os from 'node:os'
|
| 7 |
+
import { format } from 'node:util'
|
| 8 |
import { isMainThread, parentPort, Worker } from 'node:worker_threads'
|
| 9 |
import playwright from 'playwright-extra'
|
| 10 |
import prettyBytes from 'pretty-bytes'
|
|
|
|
| 21 |
const fn = new AsyncFunction('playwright', 'pluginStealth', 'console', code)
|
| 22 |
parentPort.postMessage({ result: await fn(playwright, pluginStealth, console) })
|
| 23 |
} catch (error) {
|
| 24 |
+
parentPort.postMessage({ error: format(error) })
|
| 25 |
}
|
| 26 |
})
|
| 27 |
}
|
|
|
|
| 84 |
worker.postMessage(code)
|
| 85 |
worker.on('message', ({ result, error }) => {
|
| 86 |
cleanup()
|
| 87 |
+
error ? reject(new Error(error)) : resolve(format(result))
|
| 88 |
})
|
| 89 |
worker.on('error', (err) => {
|
| 90 |
cleanup()
|
|
|
|
| 99 |
const app = new Hono()
|
| 100 |
|
| 101 |
app.use(logger())
|
| 102 |
+
app.use(prettyJSON({ force: true }))
|
| 103 |
app.use('/file/*', serveStatic({
|
| 104 |
root: os.tmpdir(),
|
| 105 |
rewriteRequestPath: (path) => path.replace(/^\/file/, '')
|
|
|
|
| 118 |
try {
|
| 119 |
return c.json({ result: await runBrowserScript(code) })
|
| 120 |
} catch (e) {
|
| 121 |
+
return c.json({ error: format(e) }, 500)
|
| 122 |
}
|
| 123 |
})
|
| 124 |
|