send subdomain on success
This commit is contained in:
parent
3d630ed1f2
commit
994fc730c5
|
|
@ -18,15 +18,14 @@ type Response = {
|
|||
body: string
|
||||
}
|
||||
|
||||
type Success = {
|
||||
subdomain: string
|
||||
}
|
||||
|
||||
type Connection = { app: string, ws: any }
|
||||
let connections: Record<string, Connection> = {}
|
||||
const pending = new Map<string, (res: any) => 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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user