sneaker wip

This commit is contained in:
Chris Wanstrath 2025-09-23 17:55:31 -07:00
parent fa01e2d306
commit 5797ff9ebc
2 changed files with 39 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import { send, addWebsocket, removeWebsocket, closeWebsockets } from "./websocke
import { Layout } from "./components/layout"
import { Terminal } from "./components/terminal"
import { dispatchMessage } from "./dispatch"
import "./sneaker"
//
// Hono setup

38
app/src/sneaker.ts Normal file
View File

@ -0,0 +1,38 @@
import app from "./server"
const SNEAKER_URL = "localhost:3100"
const ws = new WebSocket(`ws://${SNEAKER_URL}/tunnel`)
ws.onerror = e => console.log("sneaker error", e)
ws.onmessage = async event => {
const msg = JSON.parse(event.data.toString())
try {
const req = new Request("http://localhost" + msg.path, {
method: msg.method,
headers: msg.headers,
body: msg.body || undefined,
})
const res = await app.fetch(req)
const body = await res.text()
const headers: Record<string, string> = {}
res.headers.forEach((v, k) => (headers[k] = v))
ws.send(JSON.stringify({
id: msg.id,
status: res.status,
headers,
body,
}))
} catch (err: any) {
ws.send(JSON.stringify({
id: msg.id,
status: 500,
headers: { "content-type": "text/plain" },
body: "error: " + err.message,
}))
}
}