BunHttpServer.ts
BunHttpServer.ts overview
Section titled “BunHttpServer.ts overview”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.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “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>( options: ServeOptions<R> & { readonly disablePreemptiveShutdown?: boolean | undefined readonly gracefulShutdownTimeout?: Duration.Input | undefined }) => Effect.Effect< { readonly serve: { <E, R>( effect: Effect.Effect<ServerResponse.HttpServerResponse, E, R> ): Effect.Effect<void, never, Exclude<R, ServerRequest.HttpServerRequest> | Scope.Scope> <E, R, App extends Effect.Effect<ServerResponse.HttpServerResponse, any, any>>( effect: Effect.Effect<ServerResponse.HttpServerResponse, E, R>, middleware: HttpMiddleware.Applied<App, E, R> ): Effect.Effect<void, never, Exclude<R, ServerRequest.HttpServerRequest> | Scope.Scope> } readonly address: Server.Address }, never, Scope.Scope>Since v4.0.0
layers
Section titled “layers”Layer that provides a Bun HttpServer together with the Bun HTTP platform, ETag generator, and Bun services.
Signature
declare const layer: <R extends string>( options: ServeOptions<R> & { readonly disablePreemptiveShutdown?: boolean | undefined readonly gracefulShutdownTimeout?: Duration.Input | undefined }) => Layer.Layer<Server.HttpServer | HttpPlatform | Etag.Generator | BunServices.BunServices>Since v4.0.0
layerConfig
Section titled “layerConfig”Creates the Bun HTTP server and support-services layer from configurable serve options.
Signature
declare const layerConfig: <R extends string>( options: Config.Wrap< ServeOptions<R> & { readonly disablePreemptiveShutdown?: boolean | undefined readonly gracefulShutdownTimeout?: Duration.Input | undefined } >) => Layer.Layer<Server.HttpServer | HttpPlatform | FileSystem.FileSystem | Etag.Generator | Path.Path, ConfigError>Since v4.0.0
layerHttpServices
Section titled “layerHttpServices”Layer that provides Bun HTTP support services: HttpPlatform, weak ETag generation, and BunServices.
Signature
declare const layerHttpServices: Layer.Layer<BunServices.BunServices | HttpPlatform | Etag.Generator, never, never>Since v4.0.0
layerServer
Section titled “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 | undefined readonly gracefulShutdownTimeout?: Duration.Input | undefined }) => Layer.Layer<Server.HttpServer>Since v4.0.0
layerTest
Section titled “layerTest”Layer that starts a Bun HTTP server on an ephemeral port for tests.
Signature
declare const layerTest: Layer.Layer< FileSystem.FileSystem | Path.Path | Server.HttpServer | HttpPlatform | Etag.Generator | HttpClient, never, never>Since v4.0.0
options
Section titled “options”ServeOptions (type alias)
Section titled “ServeOptions (type alias)”Bun serve options accepted by the HTTP server, extended with typed route definitions.
Signature
type ServeOptions<R> = ( | Bun.Serve.UnixServeOptions<WebSocketContext> | Bun.Serve.HostnamePortServeOptions<WebSocketContext>) & { readonly routes?: Bun.Serve.Routes<WebSocketContext, R> }Since v4.0.0