Skip to content

BunHttpServer.ts

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



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
>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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
>

Source

Since v4.0.0

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> }

Source

Since v4.0.0