import type { Middleware } from "./types/index.js"; /** * CORS configuration options. * * @example * ```ts * const options: CorsOptions = { * origin: "https://myapp.com", * methods: ["GET", "POST"], * credentials: true, * maxAge: 86400, * }; * ``` */ export interface CorsOptions { /** * Allowed origin(s). Use `"*"` (default) for any origin, * a single string for one origin, or an array for multiple. * * @default "*" */ origin?: string | string[]; /** * HTTP methods to advertise in `Access-Control-Allow-Methods`. * * @default ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"] */ methods?: string[]; /** * Headers the client is allowed to send. * When omitted, the value of `Access-Control-Request-Headers` is reflected. */ allowHeaders?: string[]; /** * Response headers the browser may expose to client-side JavaScript. */ exposeHeaders?: string[]; /** * Whether to include `Access-Control-Allow-Credentials: true`. * * @default false */ credentials?: boolean; /** * How long (in seconds) the browser may cache preflight results. * Omitted from the response when `undefined`. */ maxAge?: number; } /** * Create a CORS middleware. * * Handles preflight `OPTIONS` requests (returns 204) and * adds CORS headers to actual responses. * * @param options - CORS configuration (defaults allow all origins) * @returns Middleware function * * @example * ```ts * import { createApp, cors } from "@bunary/http"; * * // Allow any origin * const app = createApp(); * app.use(cors()); * * // Restrict to a single origin with credentials * app.use(cors({ * origin: "https://myapp.com", * credentials: true, * maxAge: 86400, * })); * * // Multiple allowed origins * app.use(cors({ * origin: ["https://app1.com", "https://app2.com"], * methods: ["GET", "POST"], * })); * ``` */ export declare function cors(options?: CorsOptions): Middleware; //# sourceMappingURL=cors.d.ts.map