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

x/ayonli_jsext/http/server.ts>ServeOptions

A JavaScript extension package for building strong and modern applications.
Latest
interface ServeOptions
import { type ServeOptions } from "https://deno.land/x/ayonli_jsext@v0.9.72/http/server.ts";

Options for serving HTTP requests, used by serve.

Properties

optional
type: "classic" | "module"

Instructs how the server should be deployed. classic means serve will start the server itself (or use addEventListener("fetch") in service workers), while module means using the Server instance as an ES module with the syntax export default serve({ ... }).

NOTE: This option is only adjustable in Node.js, Deno, Bun and Cloudflare Workers, in other environments, it will be ignored and will default to classic. It is recommended to set this option to module in Cloudflare Workers.

The handler for processing HTTP requests.

optional
hostname: string | undefined

The hostname to listen on. Default is 0.0.0.0.

NOTE: This option is ignored in workers or when the type is module.

optional
port: number | undefined

The port to listen on. If not set, the server will first try to use the 8000 port, and if it's not available, it will use a random port.

NOTE: This option is ignored in workers or when the type is module.

optional
key: string | undefined

The certificate key for serving HTTPS/HTTP2 requests.

NOTE: This option is ignored in workers or when the type is module.

optional
cert: string | undefined

The certificate for serving HTTPS/HTTP2 requests.

NOTE: This option is ignored in workers or when the type is module.

optional
ws: WebSocketHandler | undefined

The WebSocket handler for processing WebSocket connections. Normally this options is not set and the WebSocket is handled per request inside the fetch handler.

optional
onError: RequestErrorHandler | undefined

A listener that will be called when the fetch handler throws an error. By default, the server will respond with a 500 Internal Server Error response, we can override this behavior by setting this option.

optional
onListen: ((info: { hostname: string; port: number; }) => void) | undefined

A listener that will be called when the server starts listening. By default, the server will log the address it's listening on, we can override this behavior by setting this option.

NOTE: This option is ignored in workers or when the type is module.

optional
headers: HeadersInit | null | undefined

Extra headers to be sent with the response. These headers are only set when they're not present.

By default, the server will set the Server header to the runtime name and its version. We can set this option to override the default behavior, or set it to null to disable the default headers.