maxM
Denoβ€’2y agoβ€’
7 replies
max

With Deno.serveHttp marked as deprecated is there a way to run an HTTP server off of a Deno.Conn?

I have a bit of weird use-case where I want to start a listener, accept the first TCP connection (and serve HTTP to it) and then reject all future TCP connections.

I have the following code:
const server = Deno.listen({
  hostname: "0.0.0.0",
  port: 0,
});
const conn = await server.accept();
(async () => {
  // Reject all additional connections.
  for await (const conn of server) {
    conn.close();
  }
})();
const httpConn = Deno.serveHttp(conn);
for await (const requestEvent of httpConn) {
// etc...


Is there a way to do this using Deno.serve, or something else?
Was this page helpful?