diff --git a/src/server.tsx b/src/server.tsx index a9032d1..520665f 100644 --- a/src/server.tsx +++ b/src/server.tsx @@ -18,15 +18,14 @@ type Response = { body: string } +type Success = { + subdomain: string +} + type Connection = { app: string, ws: any } let connections: Record = {} const pending = new Map void> -function send(connection: any, msg: Request) { - console.log("sending", msg) - connection.send(JSON.stringify(msg)) -} - const app = new Hono app.get("/tunnel", c => { @@ -40,6 +39,7 @@ app.get("/tunnel", c => { const name = randomName() connections[name] = { app, ws } console.log(`connection opened: ${name} -> ${app}`) + send(ws, { subdomain: name }) }, onClose: (_event, ws) => { for (const name of Object.keys(connections)) @@ -96,6 +96,12 @@ app.get("*", async c => { }) }) +function send(connection: any, msg: Request | Success) { + console.log("sending", msg) + connection.send(JSON.stringify(msg)) +} + + function randomID(): string { return Math.random().toString(36).slice(2, 10) }