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