@buntal/http/middlewares

cors

CORS (Cross-Origin Resource Sharing) middleware for handling cross-origin requests in Buntal applications. Answers OPTIONS preflight requests with 204; register it before auth().

Source

View source on GitHub

Type Definition

function cors(options?: CorsOptions): AtomicHandler

type CorsOptions = {
  origin?: string | string[]
  methods?: string | string[]
  allowedHeaders?: string | string[]
  exposedHeaders?: string | string[]
  maxAge?: number
  credentials?: boolean
}

Parameters

ParameterTypeRequiredDefaultDescription
optionsCorsOptions❌-CORS configuration options

Properties

PropertyTypeRequiredDefaultDescription
originstring | string[]❌*Allowed origins. An array is an allow list: the matching request origin is echoed with Vary: Origin, other origins get no CORS headers
methodsstring | string[]❌GET, HEAD, PUT, PATCH, POST, DELETEAllowed HTTP methods
allowedHeadersstring | string[]❌Content-Type, Authorization, X-Requested-WithAllowed request headers
exposedHeadersstring | string[]❌-Headers exposed to the client
maxAgenumber❌600Preflight request cache duration in seconds
credentialsboolean❌trueSend Access-Control-Allow-Credentials for allow-listed origins. Never sent with origin *

Last modified: 2026-10-02