bunway
Version:
Express-style routing toolkit built natively for Bun.
33 lines • 1.25 kB
TypeScript
import type { Handler } from "../core/router";
import type { WayContext } from "../core/context";
type OriginOptionFn = (origin: string | null, ctx: WayContext) => string | false;
type OriginOption = "*" | true | string | RegExp | (string | RegExp)[] | OriginOptionFn;
export interface CORSOptions {
origin?: OriginOption;
methods?: string[];
allowedHeaders?: string[];
exposedHeaders?: string[];
credentials?: boolean;
maxAge?: number;
allowPrivateNetwork?: boolean;
}
/**
* Bun-native CORS middleware compatible with bunWay's router finalizer.
*
* @example Allow any localhost origin and forward credentials
* ```ts
* app.use(cors({ origin: (origin) => origin?.startsWith("http://localhost") ? origin : false, credentials: true }));
* ```
*
* @example Simple allow-list
* ```ts
* app.use(cors({ origin: ["https://app.example.com", /\.my-app\.com$/] }));
* ```
*
* The middleware inspects the incoming Origin/Access-Control headers,
* determines whether the request should be allowed, and records all response
* headers so the router can apply them even if a handler returns a raw `Response`.
*/
export declare function cors(options?: CORSOptions): Handler;
export {};
//# sourceMappingURL=cors.d.ts.map