diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..6b2e534 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,67 @@ +// Type definitions for @koa/cors 3.0 +// Project: https://github.com/koajs/cors +// Definitions by: Xavier Stouder +// Izayoi Ko +// Steve Hipwell +// Steven McDowall +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import * as Koa from 'koa'; + +export = cors; + +/** + * CORS middleware factory. + * @param options - Configuration options. + * @returns cors middleware + */ +declare function cors(options?: cors.Options): Koa.Middleware; + +declare namespace cors { + /** + * Middleware configration options. + */ + interface Options { + /** + * `Access-Control-Allow-Origin`, default is request Origin header. + * + * @remarks + * If a function is provided, it will be called for each request with + * the koa context object. It may return a string or a promise that + * will resolve with a string. + */ + origin?: ((ctx: Koa.Context) => string) | ((ctx: Koa.Context) => PromiseLike) | string; + + /** + * `Access-Control-Allow-Methods`, default is + * 'GET,HEAD,PUT,POST,DELETE,PATCH' + */ + allowMethods?: string[] | string; + + /** + * `Access-Control-Expose-Headers` + */ + exposeHeaders?: string[] | string; + + /** + * `Access-Control-Allow-Headers` + */ + allowHeaders?: string[] | string; + + /** + * `Access-Control-Max-Age` in seconds + */ + maxAge?: number | string; + + /** + * `Access-Control-Allow-Credentials` + */ + credentials?: boolean; + + /** + * Add set headers to `err.header` if an error is thrown + */ + keepHeadersOnError?: boolean; + } +} diff --git a/package.json b/package.json index d4fe940..0860749 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "3.1.0", "description": "Cross-Origin Resource Sharing(CORS) for koa", "main": "index.js", + "typings": "index.d.ts", "files": [ "index.js" ],