request subdomain (maybe?)
This commit is contained in:
parent
994fc730c5
commit
80559999ab
|
|
@ -30,13 +30,16 @@ const app = new Hono
|
||||||
|
|
||||||
app.get("/tunnel", c => {
|
app.get("/tunnel", c => {
|
||||||
const app = c.req.query("app")
|
const app = c.req.query("app")
|
||||||
if (!app) {
|
if (!app)
|
||||||
return c.text("need ?app name", 502)
|
return c.text("need ?app name", 502)
|
||||||
}
|
|
||||||
|
const subdomain = c.req.query("subdomain") || ""
|
||||||
|
if (subdomain && connections[subdomain])
|
||||||
|
return c.text("subdomain taken", 502)
|
||||||
|
|
||||||
return upgradeWebSocket(c, {
|
return upgradeWebSocket(c, {
|
||||||
async onOpen(_event, ws) {
|
async onOpen(_event, ws) {
|
||||||
const name = randomName()
|
const name = subdomain || randomName()
|
||||||
connections[name] = { app, ws }
|
connections[name] = { app, ws }
|
||||||
console.log(`connection opened: ${name} -> ${app}`)
|
console.log(`connection opened: ${name} -> ${app}`)
|
||||||
send(ws, { subdomain: name })
|
send(ws, { subdomain: name })
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user