1 | // Type definitions for cors 2.8
|
---|
2 | // Project: https://github.com/expressjs/cors/
|
---|
3 | // Definitions by: Alan Plum <https://github.com/pluma>
|
---|
4 | // Gaurav Sharma <https://github.com/gtpan77>
|
---|
5 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
---|
6 | // TypeScript Version: 2.3
|
---|
7 |
|
---|
8 | import { IncomingHttpHeaders } from 'http';
|
---|
9 |
|
---|
10 | type StaticOrigin = boolean | string | RegExp | (boolean | string | RegExp)[];
|
---|
11 |
|
---|
12 | type CustomOrigin = (requestOrigin: string | undefined, callback: (err: Error | null, origin?: StaticOrigin) => void) => void;
|
---|
13 |
|
---|
14 | declare namespace e {
|
---|
15 | interface CorsRequest {
|
---|
16 | method?: string | undefined;
|
---|
17 | headers: IncomingHttpHeaders;
|
---|
18 | }
|
---|
19 | interface CorsOptions {
|
---|
20 | /**
|
---|
21 | * @default '*''
|
---|
22 | */
|
---|
23 | origin?: StaticOrigin | CustomOrigin | undefined;
|
---|
24 | /**
|
---|
25 | * @default 'GET,HEAD,PUT,PATCH,POST,DELETE'
|
---|
26 | */
|
---|
27 | methods?: string | string[] | undefined;
|
---|
28 | allowedHeaders?: string | string[] | undefined;
|
---|
29 | exposedHeaders?: string | string[] | undefined;
|
---|
30 | credentials?: boolean | undefined;
|
---|
31 | maxAge?: number | undefined;
|
---|
32 | /**
|
---|
33 | * @default false
|
---|
34 | */
|
---|
35 | preflightContinue?: boolean | undefined;
|
---|
36 | /**
|
---|
37 | * @default 204
|
---|
38 | */
|
---|
39 | optionsSuccessStatus?: number | undefined;
|
---|
40 | }
|
---|
41 | type CorsOptionsDelegate<T extends CorsRequest = CorsRequest> = (
|
---|
42 | req: T,
|
---|
43 | callback: (err: Error | null, options?: CorsOptions) => void,
|
---|
44 | ) => void;
|
---|
45 | }
|
---|
46 |
|
---|
47 | declare function e<T extends e.CorsRequest = e.CorsRequest>(
|
---|
48 | options?: e.CorsOptions | e.CorsOptionsDelegate<T>,
|
---|
49 | ): (
|
---|
50 | req: T,
|
---|
51 | res: {
|
---|
52 | statusCode?: number | undefined;
|
---|
53 | setHeader(key: string, value: string): any;
|
---|
54 | end(): any;
|
---|
55 | },
|
---|
56 | next: (err?: any) => any,
|
---|
57 | ) => void;
|
---|
58 | export = e;
|
---|