method HTTPServer.serve
HTTPServer.serve(
config?: { port: number; onListen?: (s: object) => void; onError?: (e: Error) => void; },
handler: (
req: http.IncomingMessage,
res: http.ServerResponse
) => void
): Promise<http.Server>

Creates and starts a plain http.createServer instance on the given port.

The handler gets node's own request and response, NOT this server's Request and Response: nothing in this path attaches path/query/params/json, so promising them would be a lie. The ambient augmentation this replaced told exactly that lie.

// Defined, not invoked: binds a real port.
function example() {
  return HTTPServer.serve({ port: 4200 }, (_req, res) => res.end('static-style handler'));
}

Parameters

optional
config: { port: number; onListen?: (s: object) => void; onError?: (e: Error) => void; }
handler: (
req: http.IncomingMessage,
res: http.ServerResponse
) => void

Return Type

Promise<http.Server>

Usage

import { HTTPServer } from "lib/web/index.ts";