UNPKG

2.8 kBTypeScriptView Raw
1// Type definitions for @koa/cors 4.0
2// Project: https://github.com/koajs/cors
3// Definitions by: Xavier Stouder <https://github.com/Xstoudi>
4// Steven McDowall <https://github.com/sjmcdowall>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 2.3
7
8import * as Koa from 'koa';
9
10export = cors;
11
12/**
13 * CORS middleware factory.
14 * @param options - Configuration options.
15 * @returns cors middleware
16 */
17declare function cors(options?: cors.Options): Koa.Middleware;
18
19declare namespace cors {
20 /**
21 * Middleware configration options.
22 */
23 interface Options {
24 /**
25 * `Access-Control-Allow-Origin`, default is request Origin header.
26 *
27 * @remarks
28 * If a function is provided, it will be called for each request with
29 * the koa context object. It may return a string or a promise that
30 * will resolve with a string.
31 */
32 origin?: ((ctx: Koa.Context) => string) | ((ctx: Koa.Context) => PromiseLike<string>) | string | undefined;
33
34 /**
35 * `Access-Control-Allow-Methods`, default is
36 * 'GET,HEAD,PUT,POST,DELETE,PATCH'
37 */
38 allowMethods?: string[] | string | undefined;
39
40 /**
41 * `Access-Control-Expose-Headers`
42 */
43 exposeHeaders?: string[] | string | undefined;
44
45 /**
46 * `Access-Control-Allow-Headers`
47 */
48 allowHeaders?: string[] | string | undefined;
49
50 /**
51 * `Access-Control-Max-Age` in seconds
52 */
53 maxAge?: number | string | undefined;
54
55 /**
56 * `Access-Control-Allow-Credentials`
57 *
58 * @remarks
59 * If a function is provided, it will be called for each request with
60 * the koa context object. It may return a boolean or a promise that
61 * will resolve with a boolean.
62 */
63 credentials?:
64 | ((ctx: Koa.Context) => boolean)
65 | ((ctx: Koa.Context) => PromiseLike<boolean>)
66 | boolean
67 | undefined;
68
69 /**
70 * Add set headers to `err.header` if an error is thrown
71 */
72 keepHeadersOnError?: boolean | undefined;
73
74 /**
75 * Add `Cross-Origin-Opener-Policy` & `Cross-Origin-Embedder-Policy` to response headers
76 *
77 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/Planned_changes
78 */
79 secureContext?: boolean | undefined;
80
81 /**
82 * Handle `Access-Control-Request-Private-Network` request by return `Access-Control-Allow-Private-Network`
83 *
84 * @see https://wicg.github.io/private-network-access/
85 */
86 privateNetworkAccess?: boolean | undefined;
87 }
88}
89
\No newline at end of file