Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/http.ts>Server

A JavaScript extension package for building strong and modern applications.
Latest
class Server
Re-export
import { Server } from "https://deno.land/x/ayonli_jsext@v0.9.72/http.ts";

A unified HTTP server interface.

Constructors

new
Server(impl: () => Promise<{ http:
| HttpServer
| Http2SecureServer
| BunServer
| null
; hostname: string; port: number; controller: AbortController | null; }>
, options: Pick<ServeOptions,
| "type"
| "fetch"
| "onError"
| "onListen"
| "headers"
> & { ws: WebSocketServer; secure?: boolean; }
)

Properties

private
[_controller]: AbortController | null
private
[_hostname]: string
private
[_http]: Promise<
| HttpServer
| Http2SecureServer
| BunServer
| null
>
private
[_port]: number
optional
fetch: ((
request: Request,
env?: any,
ctx?: any,
) => Response | Promise<Response>)

A request handler for using the server instance as an ES module worker, only available when the server type is module.

readonly
hostname: string

The hostname of which the server is listening on, only available after the server is ready and the server type is classic.

readonly
port: number

The port of which the server is listening on, only available after the server is ready and the server type is classic.

readonly
ready: Promise<this>

A promise that resolves when the server is ready to accept connections.

readonly
type: "classic" | "module"

Methods

close(force?): Promise<void>

Closes the server and stops it from accepting new connections. By default, this function will wait until all active connections to close before shutting down the server. However, we can force the server to close all active connections and shutdown immediately by setting the force parameter to true.

NOTE: In Node.js, the force parameter is only available for HTTP servers, it has no effect on HTTP2 servers.

ref(): void

Opposite of unref(), calling ref() on a previously unrefed server will not let the program exit if it's the only server left (the default behavior). If the server is refed calling ref() again will have no effect.

unref(): void

Calling unref() on a server will allow the program to exit if this is the only active server in the event system. If the server is already unrefed callingunref() again will have no effect.