Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typing file #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Type definitions for @koa/cors 3.0
// Project: https://github.com/koajs/cors
// Definitions by: Xavier Stouder <https://github.com/Xstoudi>
// Izayoi Ko <https://github.com/izayoiko>
// Steve Hipwell <https://github.com/stevehipwell>
// Steven McDowall <https://github.com/sjmcdowall>
// 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>) | 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;
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down