tui: fix SDK context usage and server port fallback

- Update SDK context to return client instead of event for proper usage
- Add server port fallback to 4096 when port 0 is specified but unavailable
- Fix SDK event listener usage in TUI app
This commit is contained in:
Dax Raad
2025-12-21 14:57:55 -05:00
parent 9188bc542c
commit 2536e9f45b
3 changed files with 27 additions and 13 deletions

View File

@@ -2601,13 +2601,19 @@ export namespace Server {
}
export function listen(opts: { port: number; hostname: string }) {
const server = Bun.serve({
port: opts.port,
const args = {
hostname: opts.hostname,
idleTimeout: 0,
fetch: App().fetch,
websocket: websocket,
})
return server
} as const
if (opts.port === 0) {
try {
return Bun.serve({ ...args, port: 4096 })
} catch {
// port 4096 not available, fall through to use port 0
}
}
return Bun.serve({ ...args, port: opts.port })
}
}