@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
68 lines • 1.68 kB
TypeScript
/**
* @module runtime/middleware/cors
* @description CORS (Cross-Origin Resource Sharing) middleware for Gati framework
*/
import type { Middleware } from '../types/middleware.js';
/**
* CORS middleware configuration options
*/
export interface CorsOptions {
/**
* Allowed origin(s)
* @default '*'
*/
origin?: string | string[] | ((origin: string) => boolean);
/**
* Allowed HTTP methods
* @default ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']
*/
methods?: string[];
/**
* Allowed headers
* @default ['Content-Type', 'Authorization']
*/
allowedHeaders?: string[];
/**
* Exposed headers
*/
exposedHeaders?: string[];
/**
* Allow credentials (cookies, authorization headers)
* @default false
*/
credentials?: boolean;
/**
* Preflight cache duration in seconds
* @default 86400 (24 hours)
*/
maxAge?: number;
}
/**
* Create a CORS middleware
*
* @param options - CORS configuration options
* @returns Middleware function
*
* @example
* ```typescript
* // Allow all origins
* app.use(createCorsMiddleware());
*
* // Specific origin
* app.use(createCorsMiddleware({ origin: 'https://myapp.com' }));
*
* // Multiple origins
* app.use(createCorsMiddleware({
* origin: ['https://app1.com', 'https://app2.com'],
* credentials: true
* }));
*
* // Dynamic origin validation
* app.use(createCorsMiddleware({
* origin: (origin) => origin.endsWith('.myapp.com'),
* credentials: true
* }));
* ```
*/
export declare function createCorsMiddleware(options?: CorsOptions): Middleware;
//# sourceMappingURL=cors.d.ts.map