UNPKG

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