HttpMiddleware
Constructors
Creates a CORS (Cross-Origin Resource Sharing) middleware for HTTP applications.
Signature
declare const cors: (options?: { readonly allowedHeaders?: ReadonlyArray<string>; readonly allowedMethods?: ReadonlyArray<string>; readonly allowedOrigins?: ReadonlyArray<string> | Predicate.Predicate<string>; readonly credentials?: boolean; readonly exposedHeaders?: ReadonlyArray<string>; readonly maxAge?: number;}) => <E, R>(httpApp: App.Default<E, R>) => App.Default<E, R>Example
import { HttpMiddleware, HttpRouter, HttpServerResponse } from "@effect/platform"
// Allow all origins and reflect requested headers (default behavior)HttpRouter.empty.pipe( HttpRouter.get("/", HttpServerResponse.empty()), HttpMiddleware.cors())
// Restrict to specific origins and headersHttpRouter.empty.pipe( HttpRouter.get("/", HttpServerResponse.empty()), HttpMiddleware.cors({ allowedOrigins: ["https://example.com"], allowedHeaders: ["Content-Type", "Authorization"], credentials: true }))
// Dynamic origin checking with predicateHttpRouter.empty.pipe( HttpRouter.get("/", HttpServerResponse.empty()), HttpMiddleware.cors({ allowedOrigins: (origin) => origin.endsWith(".example.com") }))Signature
declare const logger: <E, R>(httpApp: App.Default<E, R>) => App.Default<E, R>Signature
declare const make: <M extends HttpMiddleware>(middleware: M) => M Since v1.0.0 Source
Signature
declare const searchParamsParser: <E, R>(httpApp: App.Default<E, R>) => App.Default<E, Exclude<R, ServerRequest.ParsedSearchParams>> Since v1.0.0 Source
Signature
declare const xForwardedHeaders: <E, R>(httpApp: App.Default<E, R>) => App.Default<E, R>Fiber Refs
Since v1.0.0 Source
Signature
declare const currentTracerDisabledWhen: FiberRef.FiberRef<Predicate.Predicate<ServerRequest.HttpServerRequest>> Since v1.0.0 Source
Signature
declare const loggerDisabled: FiberRef.FiberRef<boolean> Since v1.0.0 Source
Signature
declare const withLoggerDisabled: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> Since v1.0.0 Source
Signature
declare const withTracerDisabledForUrls: { (urls: readonly Array<string>): <A, E, R>(layer: Layer<A, E, R>) => Layer<A, E, R>; <A, E, R>(layer: Layer<A, E, R>, urls: readonly Array<string>): Layer<A, E, R>;} Since v1.0.0 Source
Signature
declare const withTracerDisabledWhen: { (predicate: Predicate<HttpServerRequest>): <A, E, R>(layer: Layer<A, E, R>) => Layer<A, E, R>; <A, E, R>(layer: Layer<A, E, R>, predicate: Predicate<HttpServerRequest>): Layer<A, E, R>;} Since v1.0.0 Source
Signature
declare const withTracerDisabledWhenEffect: { (predicate: Predicate<HttpServerRequest>): <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>; <A, E, R>(effect: Effect<A, E, R>, predicate: Predicate<HttpServerRequest>): Effect<A, E, R>;}Models
HttpMiddleware
interface Since v1.0.0 Source
Signature
interface HttpMiddleware { <E, R>(self: Default<E, R>): Default<any, any>;}Other
Since v1.0.0 Source
Tracing
Since v1.0.0 Source
Signature
declare const SpanNameGenerator: anySpanNameGenerator
interface Since v1.0.0 Source
Signature
interface SpanNameGenerator { readonly _: typeof _;} Since v1.0.0 Source
Customizes the span name for the http app.
Signature
declare const withSpanNameGenerator: { (f: (request: HttpServerRequest) => string): <A, E, R>(layer: Layer<A, E, R>) => Layer<A, E, R>; <A, E, R>(layer: Layer<A, E, R>, f: (request: HttpServerRequest) => string): Layer<A, E, R>;}Example
import { HttpMiddleware, HttpRouter, HttpServer, HttpServerResponse} from "@effect/platform"import { NodeHttpServer, NodeRuntime } from "@effect/platform-node"import { Layer } from "effect"import { createServer } from "http"
HttpRouter.empty.pipe( HttpRouter.get("/", HttpServerResponse.empty()), HttpServer.serve(), // Customize the span names for this HttpApp HttpMiddleware.withSpanNameGenerator((request) => `GET ${request.url}`), Layer.provide(NodeHttpServer.layer(createServer, { port: 3000 })), Layer.launch, NodeRuntime.runMain)