API reference
backend({ gateway }) configures Layeron’s public Gateway runtime for CORS, request ids, trace headers, and Gateway product logs.
Import
Section titled “Import”import { backend } from "@layeron/core"backend
Section titled “backend”Create a Layeron backend app.
backend(options: BackendOptions): BackendAppGatewayConfig
Section titled “GatewayConfig”Options accepted by backend({ gateway }).
| Field | Type | Description |
|---|---|---|
cors | GatewayCorsConfig | undefined | CORS policy for Gateway responses and preflight requests. |
logs | GatewayLogConfig | undefined | Gateway product log controls. |
defaultAuth | RouteAuthPolicy | undefined | Default route auth policy when a route omits auth. |
requestIdHeader | string | undefined | Incoming header used as the request id. Defaults to x-request-id. |
responseRequestIdHeader | string | undefined | Response header that carries the request id. Defaults to x-layeron-request-id. |
traceHeader | string | undefined | Incoming trace header stored in runtime context. Defaults to traceparent. |
GatewayCorsConfig
Section titled “GatewayCorsConfig”Gateway CORS policy.
| Field | Type | Description |
|---|---|---|
origins | string[] | undefined | Allowed request origins. |
methods | HttpMethod[] | undefined | Methods allowed by CORS preflight. |
requestHeaders | string[] | undefined | Request headers allowed by CORS preflight. |
responseHeaders | string[] | undefined | Response headers exposed to browsers. |
credentials | boolean | undefined | Whether matching origins receive Access-Control-Allow-Credentials. |
maxAgeSeconds | int32 | undefined | Access-Control-Max-Age value in seconds. |
GatewayLogConfig
Section titled “GatewayLogConfig”Gateway product log controls.
| Field | Type | Description |
|---|---|---|
level | ObservabilitySeverity | undefined | Minimum Gateway product log level. |
request | boolean | undefined | Whether request lifecycle logs are emitted. |
cors | boolean | undefined | Whether CORS decision logs are emitted. |
routeMatch | boolean | undefined | Whether route matching diagnostics are emitted. |
errors | boolean | undefined | Whether normalized Gateway error logs are emitted. |
includeHeaders | string[] | undefined | Header allowlist for log attributes. |
redactHeaders | string[] | undefined | Additional headers to redact when included. |
sampling | Layeron.Observability.SamplingPolicy | undefined | Sampling policy for Gateway logs. |
BackendOptions
Section titled “BackendOptions”Options accepted by backend().
| Field | Type | Description |
|---|---|---|
project | string | Immutable project slug. |
gateway | GatewayConfig | undefined | Gateway runtime settings. |
BackendApp
Section titled “BackendApp”Layeron backend app returned by backend().
| Field | Type | Description |
|---|---|---|
project | string | Project slug. |
gateway | GatewayConfig | undefined | Gateway runtime settings. |