NodeHttpServer
Node.js implementation of the Effect HttpServer.
This module adapts a supplied Node http.Server into Effect's
platform-independent HTTP server service. It starts the server with Node
listen options, converts request events into HttpServerRequest values,
writes HttpServerResponse bodies through Node's ServerResponse, and
handles upgrade events by exposing the upgraded socket through
HttpServerRequest.upgrade. It also exports request and upgrade handler
constructors plus layers for the server alone, HTTP support services, the
combined server, configurable options, and tests.
Constructors
Creates a scoped HttpServer from a Node http.Server, starts listening
with the supplied options, registers request and upgrade handling, and closes
the server during scope finalization with optional graceful-shutdown control.
Signature
declare const make: (...args: [evaluate: LazyArg<Server<typeof IncomingMessage, typeof ServerResponse>>, options: Options]) => 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>Handlers
makeHandler
Creates a Node request event handler for an Effect HTTP application,
injecting a HttpServerRequest and interrupting the request fiber if the
client closes the response before it finishes.
Signature
declare function makeHandler<R, E, App extends Effect<HttpServerResponse, any, any> = Effect<HttpServerResponse, E, R>>(httpEffect: Effect<HttpServerResponse, E, R>, options: { readonly middleware?: Applied<App, E, R>; readonly scope: Scope;}): Effect<(nodeRequest: IncomingMessage, nodeResponse: ServerResponse) => void, never, Exclude<Services<App>, Scope | HttpServerRequest>>makeUpgradeHandler
Creates a Node upgrade event handler for an Effect HTTP application,
exposing the upgraded WebSocket as the request's upgrade effect and
interrupting the request fiber when the socket closes early.
Signature
declare function makeUpgradeHandler<R, E, App extends Effect<HttpServerResponse, any, any> = Effect<HttpServerResponse, E, R>>(lazyWss: Effect<WebSocketServer>, httpEffect: Effect<HttpServerResponse, E, R>, options: { readonly middleware?: Applied<App, E, R>; readonly scope: Scope;}): Effect<(nodeRequest: IncomingMessage, socket: Duplex, head: Buffer) => void, never, Exclude<Services<App>, Scope | HttpServerRequest>>Layers
Provides a Node HttpServer together with the Node HTTP platform, ETag, and
core platform services required to serve requests.
Signature
declare function layer(evaluate: LazyArg<Server<typeof IncomingMessage, typeof ServerResponse>>, options: Options): Layer<HttpPlatform | Generator | NodeServices | HttpServer, ServeError>layerConfig
Provides a Node HttpServer together with the Node HTTP platform, ETag,
and core Node platform services, reading the listen and shutdown options from
a Config value.
Signature
declare function layerConfig(evaluate: LazyArg<Server<typeof IncomingMessage, typeof ServerResponse>>, options: { readonly backlog?: Config<number | undefined>; readonly disablePreemptiveShutdown?: Config<boolean | undefined>; readonly exclusive?: Config<boolean | undefined>; readonly gracefulShutdownTimeout?: Config<Input | undefined>; readonly handle?: Config<BoundSocket | undefined>; readonly host?: Config<string | undefined>; readonly ipv6Only?: Config<boolean | undefined>; readonly path?: Config<string | undefined>; readonly port?: Config<number | undefined>; readonly readableAll?: Config<boolean | undefined>; readonly reusePort?: Config<boolean | undefined>; readonly signal?: { readonly aborted: Config<boolean>; addEventListener: Config<{ <K extends "abort">(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; }>; dispatchEvent: Config<(event: Event) => boolean>; readonly onabort: Config<(this: AbortSignal, ev: Event) => any | null>; readonly reason: Config<any>; removeEventListener: Config<{ <K extends "abort">(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; }>; throwIfAborted: Config<() => void>; } | Config<AbortSignal | undefined>; readonly websocket?: Config<Omit<ServerOptions, "noServer" | "server" | "host" | "port" | "path"> | undefined>; readonly writableAll?: Config<boolean | undefined>;} | Config<Options>): Layer<HttpPlatform | Generator | NodeServices | HttpServer, ConfigError | ServeError>layerHttpServices
Provides the Node HTTP support services used by NodeHttpServer, including
the HTTP platform, ETag generator, and core Node platform services.
Signature
declare const layerHttpServices: Layer.Layer<NodeServices.NodeServices | HttpPlatform.HttpPlatform | Etag.Generator>layerServer
Provides an HttpServer by creating and managing a scoped Node
http.Server with the supplied listen and shutdown options.
Signature
declare const layerServer: (evaluate: LazyArg<Http.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse>>, options: Options) => Layer.Layer<HttpServer.HttpServer, ServeError>Options
Options accepted by the Node HttpServer constructors and layers.
Signature
interface Options extends ListenOptions { readonly disablePreemptiveShutdown?: boolean; readonly gracefulShutdownTimeout?: Input; readonly websocket?: Omit<ServerOptions, "noServer" | "server" | "host" | "port" | "path">;}Testing
Provides a test HTTP server listening on an ephemeral port together with a
Fetch-backed HttpClient configured for server integration tests.
Signature
declare const layerTest: Layer.Layer<HttpServer.HttpServer | FileSystem.FileSystem | Path.Path | HttpPlatform.HttpPlatform | Etag.Generator | HttpClient, ServeError, never>