Server

Type aliases for Bun's server primitives, parameterized for corpus.

Bun's server and socket types take the per-connection data type as a parameter. Corpus always stores a WebSocketRoute there — that is how a live socket knows which route's callbacks to invoke — so these aliases pin it once instead of at every use site.

Nothing here is a runtime construct; these are the shapes App builds and hands to Bun.serve.

Contents
  1. Server
  2. ServerHandler
  3. ServerRouteMap
  4. ServerWebSocket

Server

type

type Server = Bun.Server<WebSocketRoute>;

The running Bun server, as held by App.server.

ServerHandler

type

type ServerHandler = (request: Request, server: Maybe<Server>) => MaybePromise<Optional<Response>>;

A compiled request handler, as produced by App.finalize.

This is the form both a route map entry and the fetch fallback take. The response is optional because a WebSocketRoute upgrades the connection instead of responding.

Parameters

Returns — The response, or nothing when the connection was upgraded.

ServerRouteMap

type

type ServerRouteMap = Record<string, Partial<Record<Method, ServerHandler>>>;

The route table handed to Bun.serve, keyed by endpoint and then by Method. Built by App.composeRoutes; anything it does not match falls through to App.composeFetch.

ServerWebSocket

type

type ServerWebSocket = Bun.ServerWebSocket<WebSocketRoute>;

A live WebSocket connection. Its data is the WebSocketRoute that accepted the upgrade, which is what App.createServer dispatches the open, message and close events through.