UNPKG

2.47 kBMarkdownView Raw
1# Installation
2> `npm install --save @types/cors`
3
4# Summary
5This package contains type definitions for cors (https://github.com/expressjs/cors/).
6
7# Details
8Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cors.
9## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cors/index.d.ts)
10````ts
11// Type definitions for cors 2.8
12// Project: https://github.com/expressjs/cors/
13// Definitions by: Alan Plum <https://github.com/pluma>
14// Gaurav Sharma <https://github.com/gtpan77>
15// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
16// TypeScript Version: 2.3
17
18import { IncomingHttpHeaders } from 'http';
19
20type StaticOrigin = boolean | string | RegExp | (boolean | string | RegExp)[];
21
22type CustomOrigin = (requestOrigin: string | undefined, callback: (err: Error | null, origin?: StaticOrigin) => void) => void;
23
24declare namespace e {
25 interface CorsRequest {
26 method?: string | undefined;
27 headers: IncomingHttpHeaders;
28 }
29 interface CorsOptions {
30 /**
31 * @default '*''
32 */
33 origin?: StaticOrigin | CustomOrigin | undefined;
34 /**
35 * @default 'GET,HEAD,PUT,PATCH,POST,DELETE'
36 */
37 methods?: string | string[] | undefined;
38 allowedHeaders?: string | string[] | undefined;
39 exposedHeaders?: string | string[] | undefined;
40 credentials?: boolean | undefined;
41 maxAge?: number | undefined;
42 /**
43 * @default false
44 */
45 preflightContinue?: boolean | undefined;
46 /**
47 * @default 204
48 */
49 optionsSuccessStatus?: number | undefined;
50 }
51 type CorsOptionsDelegate<T extends CorsRequest = CorsRequest> = (
52 req: T,
53 callback: (err: Error | null, options?: CorsOptions) => void,
54 ) => void;
55}
56
57declare function e<T extends e.CorsRequest = e.CorsRequest>(
58 options?: e.CorsOptions | e.CorsOptionsDelegate<T>,
59): (
60 req: T,
61 res: {
62 statusCode?: number | undefined;
63 setHeader(key: string, value: string): any;
64 end(): any;
65 },
66 next: (err?: any) => any,
67) => void;
68export = e;
69
70````
71
72### Additional Details
73 * Last updated: Fri, 09 Jul 2021 07:31:29 GMT
74 * Dependencies: none
75 * Global values: none
76
77# Credits
78These definitions were written by [Alan Plum](https://github.com/pluma), and [Gaurav Sharma](https://github.com/gtpan77).
79
\No newline at end of file