Skip to content

API reference

backend({ gateway }) configures Layeron’s public Gateway runtime for CORS, request ids, trace headers, and Gateway product logs.

Terminal window
import { backend } from "@layeron/core"

Create a Layeron backend app.

Terminal window
backend(options: BackendOptions): BackendApp

Options accepted by backend({ gateway }).

FieldTypeDescription
corsGatewayCorsConfig | undefinedCORS policy for Gateway responses and preflight requests.
logsGatewayLogConfig | undefinedGateway product log controls.
defaultAuthRouteAuthPolicy | undefinedDefault route auth policy when a route omits auth.
requestIdHeaderstring | undefinedIncoming header used as the request id. Defaults to x-request-id.
responseRequestIdHeaderstring | undefinedResponse header that carries the request id. Defaults to x-layeron-request-id.
traceHeaderstring | undefinedIncoming trace header stored in runtime context. Defaults to traceparent.

Gateway CORS policy.

FieldTypeDescription
originsstring[] | undefinedAllowed request origins.
methodsHttpMethod[] | undefinedMethods allowed by CORS preflight.
requestHeadersstring[] | undefinedRequest headers allowed by CORS preflight.
responseHeadersstring[] | undefinedResponse headers exposed to browsers.
credentialsboolean | undefinedWhether matching origins receive Access-Control-Allow-Credentials.
maxAgeSecondsint32 | undefinedAccess-Control-Max-Age value in seconds.

Gateway product log controls.

FieldTypeDescription
levelObservabilitySeverity | undefinedMinimum Gateway product log level.
requestboolean | undefinedWhether request lifecycle logs are emitted.
corsboolean | undefinedWhether CORS decision logs are emitted.
routeMatchboolean | undefinedWhether route matching diagnostics are emitted.
errorsboolean | undefinedWhether normalized Gateway error logs are emitted.
includeHeadersstring[] | undefinedHeader allowlist for log attributes.
redactHeadersstring[] | undefinedAdditional headers to redact when included.
samplingLayeron.Observability.SamplingPolicy | undefinedSampling policy for Gateway logs.

Options accepted by backend().

FieldTypeDescription
projectstringImmutable project slug.
gatewayGatewayConfig | undefinedGateway runtime settings.

Layeron backend app returned by backend().

FieldTypeDescription
projectstringProject slug.
gatewayGatewayConfig | undefinedGateway runtime settings.