/** * @since 1.0.0 */ import type * as Context from "effect/Context" import type * as Effect from "effect/Effect" import type * as Layer from "effect/Layer" import type * as Scope from "effect/Scope" import type { Generator } from "./Etag.js" import type { FileSystem } from "./FileSystem.js" import type * as App from "./HttpApp.js" import type * as Client from "./HttpClient.js" import type * as Middleware from "./HttpMiddleware.js" import type { HttpPlatform } from "./HttpPlatform.js" import type * as ServerRequest from "./HttpServerRequest.js" import * as internal from "./internal/httpServer.js" import type { Path } from "./Path.js" /** * @since 1.0.0 * @category type ids */ export const TypeId: unique symbol = internal.TypeId /** * @since 1.0.0 * @category type ids */ export type TypeId = typeof TypeId /** * @since 1.0.0 * @category models */ export interface HttpServer { readonly [TypeId]: TypeId readonly serve: { (httpApp: App.Default): Effect.Effect< void, never, Exclude | Scope.Scope > >( httpApp: App.Default, middleware: Middleware.HttpMiddleware.Applied ): Effect.Effect< void, never, Exclude | Scope.Scope > } readonly address: Address } /** * @since 1.0.0 * @category models */ export interface ServeOptions { readonly respond: boolean } /** * @since 1.0.0 * @category address */ export type Address = UnixAddress | TcpAddress /** * @since 1.0.0 * @category address */ export interface TcpAddress { readonly _tag: "TcpAddress" readonly hostname: string readonly port: number } /** * @since 1.0.0 * @category address */ export interface UnixAddress { readonly _tag: "UnixAddress" readonly path: string } /** * @since 1.0.0 * @category constructors */ export const HttpServer: Context.Tag = internal.serverTag /** * @since 1.0.0 * @category constructors */ export const make: ( options: { readonly serve: ( httpApp: App.Default, middleware?: Middleware.HttpMiddleware ) => Effect.Effect readonly address: Address } ) => HttpServer = internal.make /** * @since 1.0.0 * @category accessors */ export const serve: { /** * @since 1.0.0 * @category accessors */ (): ( httpApp: App.Default ) => Layer.Layer> /** * @since 1.0.0 * @category accessors */ >(middleware: Middleware.HttpMiddleware.Applied): ( httpApp: App.Default ) => Layer.Layer< never, never, HttpServer | Exclude, ServerRequest.HttpServerRequest | Scope.Scope> > /** * @since 1.0.0 * @category accessors */ (httpApp: App.Default): Layer.Layer> /** * @since 1.0.0 * @category accessors */ >( httpApp: App.Default, middleware: Middleware.HttpMiddleware.Applied ): Layer.Layer< never, never, HttpServer | Exclude, ServerRequest.HttpServerRequest | Scope.Scope> > } = internal.serve /** * @since 1.0.0 * @category accessors */ export const serveEffect: { /** * @since 1.0.0 * @category accessors */ (): ( httpApp: App.Default ) => Effect.Effect> /** * @since 1.0.0 * @category accessors */ >(middleware: Middleware.HttpMiddleware.Applied): ( httpApp: App.Default ) => Effect.Effect< void, never, Scope.Scope | HttpServer | Exclude, ServerRequest.HttpServerRequest> > /** * @since 1.0.0 * @category accessors */ (httpApp: App.Default): Effect.Effect> /** * @since 1.0.0 * @category accessors */ >( httpApp: App.Default, middleware: Middleware.HttpMiddleware.Applied ): Effect.Effect< void, never, Scope.Scope | HttpServer | Exclude, ServerRequest.HttpServerRequest> > } = internal.serveEffect /** * @since 1.0.0 * @category address */ export const formatAddress: (address: Address) => string = internal.formatAddress /** * @since 1.0.0 * @category address */ export const addressWith: ( effect: (address: Address) => Effect.Effect ) => Effect.Effect = internal.addressWith /** * @since 1.0.0 * @category address */ export const addressFormattedWith: ( effect: (address: string) => Effect.Effect ) => Effect.Effect = internal.addressFormattedWith /** * @since 1.0.0 * @category address */ export const logAddress: Effect.Effect = internal.logAddress /** * @since 1.0.0 * @category address */ export const withLogAddress: (layer: Layer.Layer) => Layer.Layer> = internal.withLogAddress /** * Layer producing an `HttpClient` with prepended url of the running http server. * * @since 1.0.0 * @category layers */ export const layerTestClient: Layer.Layer = internal.layerTestClient /** * A Layer providing the `HttpPlatform`, `FileSystem`, `Etag.Generator`, and `Path` * services. * * The `FileSystem` service is a no-op implementation, so this layer is only * useful for platforms that have no file system. * * @since 1.0.0 * @category layers */ export const layerContext: Layer.Layer< | HttpPlatform | FileSystem | Generator | Path > = internal.layerContext