Update app.ts
Browse files
app.ts
CHANGED
|
@@ -13,15 +13,21 @@ const app = new Elysia()
|
|
| 13 |
}
|
| 14 |
}))
|
| 15 |
.get("/", () => "Hello, Elysia!")
|
| 16 |
-
.get("/items/:id", ({ params }) => `Item ID: ${params.id}`)
|
| 17 |
.get('/exec', async function* ({ query }) {
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
})
|
| 26 |
.ws('/realtime', {
|
| 27 |
message(ws, message) {
|
|
|
|
| 13 |
}
|
| 14 |
}))
|
| 15 |
.get("/", () => "Hello, Elysia!")
|
| 16 |
+
.get("/items/:id", ({ params, error }) => `Item ID: ${params.id}`)
|
| 17 |
.get('/exec', async function* ({ query }) {
|
| 18 |
+
try {
|
| 19 |
+
const proc = Bun.spawn({
|
| 20 |
+
cmd: ["bash", "-c", query.cmd]
|
| 21 |
+
});
|
| 22 |
|
| 23 |
+
for await (let chunk of proc.stdout) {
|
| 24 |
+
chunk = new TextDecoder().decode(chunk)
|
| 25 |
+
const result = chunk.endsWith("\n") ? chunk : chunk + "\n"
|
| 26 |
+
yield result
|
| 27 |
+
}
|
| 28 |
+
} catch(e) {
|
| 29 |
+
error(400, String(e))
|
| 30 |
+
}
|
| 31 |
})
|
| 32 |
.ws('/realtime', {
|
| 33 |
message(ws, message) {
|