sneaker wip
This commit is contained in:
parent
fa01e2d306
commit
5797ff9ebc
|
|
@ -13,6 +13,7 @@ import { send, addWebsocket, removeWebsocket, closeWebsockets } from "./websocke
|
||||||
import { Layout } from "./components/layout"
|
import { Layout } from "./components/layout"
|
||||||
import { Terminal } from "./components/terminal"
|
import { Terminal } from "./components/terminal"
|
||||||
import { dispatchMessage } from "./dispatch"
|
import { dispatchMessage } from "./dispatch"
|
||||||
|
import "./sneaker"
|
||||||
|
|
||||||
//
|
//
|
||||||
// Hono setup
|
// Hono setup
|
||||||
|
|
|
||||||
38
app/src/sneaker.ts
Normal file
38
app/src/sneaker.ts
Normal 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,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user