UNPKG

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