UNPKG

2.25 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/// <reference types="node" />
12
13import { IncomingHttpHeaders } from "http";
14
15type StaticOrigin = boolean | string | RegExp | Array<boolean | string | RegExp>;
16
17type CustomOrigin = (
18 requestOrigin: string | undefined,
19 callback: (err: Error | null, origin?: StaticOrigin) => void,
20) => void;
21
22declare namespace e {
23 interface CorsRequest {
24 method?: string | undefined;
25 headers: IncomingHttpHeaders;
26 }
27 interface CorsOptions {
28 /**
29 * @default '*''
30 */
31 origin?: StaticOrigin | CustomOrigin | undefined;
32 /**
33 * @default 'GET,HEAD,PUT,PATCH,POST,DELETE'
34 */
35 methods?: string | string[] | undefined;
36 allowedHeaders?: string | string[] | undefined;
37 exposedHeaders?: string | string[] | undefined;
38 credentials?: boolean | undefined;
39 maxAge?: number | undefined;
40 /**
41 * @default false
42 */
43 preflightContinue?: boolean | undefined;
44 /**
45 * @default 204
46 */
47 optionsSuccessStatus?: number | undefined;
48 }
49 type CorsOptionsDelegate<T extends CorsRequest = CorsRequest> = (
50 req: T,
51 callback: (err: Error | null, options?: CorsOptions) => void,
52 ) => void;
53}
54
55declare function e<T extends e.CorsRequest = e.CorsRequest>(
56 options?: e.CorsOptions | e.CorsOptionsDelegate<T>,
57): (
58 req: T,
59 res: {
60 statusCode?: number | undefined;
61 setHeader(key: string, value: string): any;
62 end(): any;
63 },
64 next: (err?: any) => any,
65) => void;
66export = e;
67
68````
69
70### Additional Details
71 * Last updated: Mon, 20 Nov 2023 23:36:24 GMT
72 * Dependencies: [@types/node](https://npmjs.com/package/@types/node)
73
74# Credits
75These definitions were written by [Alan Plum](https://github.com/pluma), and [Gaurav Sharma](https://github.com/gtpan77).
76
\No newline at end of file