BunHttpServer
Bun implementation of the Effect HttpServer.
make creates a scoped HTTP server from Bun.serve, converting Bun
Request values into HttpServerRequest values and Effect
HttpServerResponse values back into Web Response values. The server
supports streaming bodies, multipart requests, file responses through
BunHttpPlatform, and WebSocket upgrades. This module also provides layers
for the server alone, the Bun HTTP support services, the combined server,
configurable server options, and a test server with an HTTP client.
Constructors
Creates a scoped Bun HttpServer from Bun.serve options, stopping the server on scope finalization with optional graceful shutdown settings.
Signature
declare const make: <R extends string>(...args: [options: any]) => Effect<{ readonly address: Address; readonly serve: { <E, R>(effect: Effect<HttpServerResponse, E, R>): Effect<void, never, Scope | Exclude<R, HttpServerRequest>>; <E, R, App extends Effect<HttpServerResponse, any, any>>(effect: Effect<HttpServerResponse, E, R>, middleware: Applied<App, E, R>): Effect<void, never, Scope | Exclude<R, HttpServerRequest>>; };}, ServeError, Scope>Layers
Layer that provides a Bun HttpServer together with the Bun HTTP platform, ETag generator, and Bun services.
Signature
declare function layer<R extends string>(options: any): Layer<HttpPlatform | Generator | BunServices | HttpServer, ServeError>layerConfig
Creates the Bun HTTP server and support-services layer from configurable serve options.
Signature
declare function layerConfig<R extends string>(options: Config<any>): Layer<HttpPlatform | Generator | FileSystem | Path | HttpServer, ServeError | ConfigError>layerHttpServices
Layer that provides Bun HTTP support services: HttpPlatform, weak ETag generation, and BunServices.
Signature
declare const layerHttpServices: Layer.Layer<HttpPlatform | Etag.Generator | BunServices.BunServices>layerServer
Layer that provides only HttpServer by constructing a scoped Bun server from the supplied serve options.
Signature
declare const layerServer: <R extends string>(options: ServeOptions<R> & { readonly disablePreemptiveShutdown?: boolean; readonly gracefulShutdownTimeout?: Duration.Input; readonly websocket?: WebSocketOptions;}) => Layer.Layer<Server.HttpServer, Error.ServeError>Options
ServeOptions type
Bun serve options accepted by the HTTP server, extended with typed route definitions.
Signature
type ServeOptions<R extends string> = Bun.Serve.UnixServeOptions<WebSocketContext> | Bun.Serve.HostnamePortServeOptions<WebSocketContext> & { readonly routes?: Bun.Serve.Routes<WebSocketContext, R>;}WebSocketOptions type
WebSocket tuning options forwarded to Bun.serve's websocket handler.
Details
The lifecycle handlers (open, message, close, ...) are managed by the
server and cannot be overridden; everything else — such as
perMessageDeflate compression, payload limits, and idle timeouts — passes
through, e.g.
BunHttpServer.layer({ port: 3000, websocket: { perMessageDeflate: true } }).
The compressionThreshold option controls the minimum message size in bytes
that is compressed when per-message deflate is negotiated. It defaults to
1024, matching the default threshold of Node's ws server.
Signature
type WebSocketOptions = Omit<Bun.WebSocketHandler<WebSocketContext>, "open" | "message" | "close" | "drain" | "ping" | "pong" | "data" | "binaryType"> & { readonly compressionThreshold?: number;}