hono
hono copied to clipboard
[Discussion] A 'listen' function for Hono seems a good pattern?
What is the feature you are proposing?
@Hono/node-server is really great lib for the Web Standard web framework to handle IncomingMessage, and I'm using it in EdgeQL, and implementation like this,
import { serve } from '@hono/node-server'
import { EdgeQL } from '../'
export class NodeEdgeQL extends EdgeQL {
listen(
{ port, hostname }: { port?: number; hostname?: string },
listener?: (info: { address: string; family: string; port: number }) => void
): void {
serve(
{
fetch: this.fetch,
port: port ?? 3000,
hostname: hostname ?? '0.0.0.0',
},
listener
)
}
}
Then we start a server just just call listen by invoking instance function.
const app = new Hono()
app.listen(3000, (info) => { })
Hi @metrue !
Sorry if my understanding is wrong.
I think adding a listen method to Hono is not good. If listen is a method for "server", then Hono should not have it. This is because Hono makes the "server" a black box. I think the server role is done by Cloudflare workerd, Deno or Bun runtime, or Node Adapter.