Skip to main content Link Search Menu Expand Document (external link)

Middlewares overview

Mechanism for extendning behaviour of all handlers on the server.

Added in v1.0.0


Table of contents


authorization

basicAuth

Basic auth middleware.

Signature

export declare const basicAuth: <R2, _>(
  checkCredentials: (credentials: BasicAuthCredentials) => Effect.Effect<_, HttpError.HttpError, R2>,
  options?: Partial<{ headerName: string; skipPaths: ReadonlyArray<string> }>
) => <R1, E>(app: HttpServer.app.Default<E, R1>) => HttpServer.app.Default<E, R2 | R1>

Added in v1.0.0

cors

Basic auth middleware.

Signature

export declare const cors: (
  options?: Partial<CorsOptions>
) => <R, E>(app: HttpServer.app.Default<E, R>) => HttpServer.app.Default<E, R>

Added in v1.0.0

logging

accessLog

Add access logs for handled requests. The log runs before each request. Optionally configure log level using the first argument. The default log level is Debug.

Signature

export declare const accessLog: (
  level?: "Info" | "Warning" | "Debug"
) => <R, E>(app: HttpServer.app.Default<E, R>) => HttpServer.app.Default<E, R>

Added in v1.0.0

errorLog

Logs out a handler failure.

Signature

export declare const errorLog: <R, E>(app: HttpServer.app.Default<E, R>) => HttpServer.app.Default<E, R>

Added in v1.0.0

uuidLogAnnotation

Annotate request logs using generated UUID. The default annotation key is requestId. The annotation key is configurable using the first argument.

Note that in order to apply the annotation also for access logging, you should make sure the accessLog middleware is plugged after the uuidLogAnnotation.

Signature

export declare const uuidLogAnnotation: (
  logAnnotationKey?: string
) => <R, E>(app: HttpServer.app.Default<E, R>) => HttpServer.app.Default<E, R>

Added in v1.0.0

metrics

endpointCallsMetric

Measure how many times each endpoint was called in a server.endpoint_calls counter metrics.

Signature

export declare const endpointCallsMetric: () => <R, E>(
  app: HttpServer.app.Default<E, R>
) => HttpServer.app.Default<E, R>

Added in v1.0.0

models

BasicAuthCredentials (interface)

Signature

export interface BasicAuthCredentials {
  user: string
  password: string
}

Added in v1.0.0

CorsOptions (interface)

Signature

export interface CorsOptions {
  allowedOrigins: ReadonlyArray<string>
  allowedMethods: ReadonlyArray<string>
  allowedHeaders: ReadonlyArray<string>
  exposedHeaders: ReadonlyArray<string>
  maxAge: number
  credentials: boolean
}

Added in v1.0.0