diff options
author | polwex <polwex@sortug.com> | 2025-09-17 21:45:18 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-09-17 21:45:18 +0700 |
commit | 985fa2f7c99832cdf3c3351d2273c8fd05402b78 (patch) | |
tree | bc727486a89ad05e588754f8de8b1096400a3d31 /shim/ws-shim/src/server.ts | |
parent | f0df4c7297a05bd592d8717b8997284c80fd0500 (diff) |
basic comms working
Diffstat (limited to 'shim/ws-shim/src/server.ts')
-rw-r--r-- | shim/ws-shim/src/server.ts | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/shim/ws-shim/src/server.ts b/shim/ws-shim/src/server.ts index f375fc7..4632704 100644 --- a/shim/ws-shim/src/server.ts +++ b/shim/ws-shim/src/server.ts @@ -1,41 +1,10 @@ -import EventEmitter from "events"; import Urbit from "urbit-http"; -const SHIP_URL = "http://localhost:8080"; -const api = new Urbit(SHIP_URL, ""); -let sub: number; -// const emitter = new EventEmitter(); - -// //github.com/oven-sh/bun/issues/13811 -// function sse(req: Request, channel: string): Response { -// const stream = new ReadableStream({ -// type: "direct", -// pull(controller: ReadableStreamDirectController) { -// let id = +(req.headers.get("last-event-id") ?? 1); -// const handler = async (event: string, data: unknown): Promise<void> => { -// await controller.write(`id:${id}\n`); -// await controller.write(`event:${event}\n`); -// if (data) await controller.write(`data:${JSON.stringify(data)}\n\n`); -// await controller.flush(); -// id++; -// emitter.on(channel, handler); -// if (req.signal.aborted) { -// emitter.off(channel, handler); -// controller.close(); -// } -// }; -// return new Promise(() => void 0); -// }, -// }); -// return new Response(stream, { -// status: 200, -// headers: { "Content-Type": "text/event-stream" }, -// }); -// } +let SHIP_URL: URL; function emit(res: ShimResponse): void { // emitter.emit(channel, event, data); const body = JSON.stringify({ ws: res }); - fetch(SHIP_URL + "/nostr-shim", { + fetch(SHIP_URL! + "/nostr-shim", { method: "PUT", headers: { "Content-type": "application/json" }, body, @@ -48,6 +17,13 @@ const server = Bun.serve({ //http routes: { "/shim": async (req: Request) => { + console.log("req", req); + const uri = req.headers.get("origin"); + console.log({ uri }); + const url = URL.parse(uri!)!; + url.pathname = ""; + SHIP_URL = url; + const data = (await req.json()) as ShimRequest; console.log({ data }); if ("ws" in data) { |