diff --git a/types/koa-sslify/index.d.ts b/types/koa-sslify/index.d.ts index 0bf6c0a1ff..418b330586 100644 --- a/types/koa-sslify/index.d.ts +++ b/types/koa-sslify/index.d.ts @@ -1,25 +1,80 @@ -// Type definitions for koa-sslify 2.1 +// Type definitions for koa-sslify 4.0 // Project: https://github.com/turboMaCk/koa-sslify#readme // Definitions by: Matthew Bull +// Mihkel Sokk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -import * as koa from 'koa'; +import * as koa from "koa"; declare namespace sslify { - interface Options { - trustProtoHeader?: boolean; - trustAzureHeader?: boolean; - port?: number; - hostname?: string; - ignoreUrl?: boolean; - temporary?: boolean; - redirectMethods?: string[]; - internalRedirectMethods?: string[]; - specCompliantDisallow?: boolean; - } + interface Options { + /** + * Function used to test if request is secure + */ + resolver?: (ctx: koa.Context) => boolean; + /** + * Hostname for redirect (uses request host if not set) + */ + hostname?: string; + /** + * Port of HTTPS server + */ + port?: number; + /** + * Avoid :443 port in redirect url + */ + skipDefaultPort?: boolean; + /** + * Ignore url path (redirect to domain) + */ + ignoreUrl?: boolean; + /** + * Temporary mode (use 307 Temporary Redirect) + */ + temporary?: boolean; + /** + * Whitelist methods that should be redirected + */ + redirectMethods?: string[]; + /** + * Status returned for disallowed methods + */ + disallowStatus?: number; + } + + /** + * Default HTTPS resolver + * This works when using node.js TLS support + */ + function httpsResolver(ctx: koa.Context): boolean; + + /** + * x-forwarded-proto header resolver + * common for heroku gcp (ingress) etc + */ + function xForwardedProtoResolver(ctx: koa.Context): boolean; + + /** + * Azure resolver + * Azure is using `x-att-ssl` header + */ + function azureResolver(ctx: koa.Context): boolean; + + /** + * Custom proto header factory + */ + function customProtoHeaderResolver( + header: string + ): (ctx: koa.Context) => boolean; + + /** + * Resolver for `Forwarded` header + * see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded + */ + function forwardedResolver(ctx: koa.Context): boolean; } -declare function sslify(options: sslify.Options): koa.Middleware; +declare function sslify(options?: sslify.Options): koa.Middleware; export = sslify; diff --git a/types/koa-sslify/koa-sslify-tests.ts b/types/koa-sslify/koa-sslify-tests.ts index c8dae23bb4..7c87c7c705 100644 --- a/types/koa-sslify/koa-sslify-tests.ts +++ b/types/koa-sslify/koa-sslify-tests.ts @@ -1,40 +1,50 @@ import Koa = require('koa'); import sslify = require('koa-sslify'); +new Koa().use(sslify()); + new Koa().use(sslify({})); new Koa().use(sslify({ - trustAzureHeader: true, + resolver: sslify.xForwardedProtoResolver, })); new Koa().use(sslify({ - trustProtoHeader: true, + resolver: sslify.azureResolver, })); new Koa().use(sslify({ - specCompliantDisallow: true, + resolver: sslify.customProtoHeaderResolver('x-protocol'), })); new Koa().use(sslify({ - port: 1234, + resolver: sslify.forwardedResolver, })); new Koa().use(sslify({ - hostname: 'my-host', + disallowStatus: 405, })); new Koa().use(sslify({ - temporary: false, + port: 1234, })); new Koa().use(sslify({ - internalRedirectMethods: ['GET'], + hostname: 'my-host', })); new Koa().use(sslify({ - redirectMethods: ['GET'], + temporary: false, })); new Koa().use(sslify({ - ignoreUrl: true, + redirectMethods: ['GET'], +})); + +new Koa().use(sslify({ + skipDefaultPort: false, +})); + +new Koa().use(sslify({ + ignoreUrl: true, })); diff --git a/types/koa-sslify/tsconfig.json b/types/koa-sslify/tsconfig.json index 775b453de9..8c1672161b 100644 --- a/types/koa-sslify/tsconfig.json +++ b/types/koa-sslify/tsconfig.json @@ -1,23 +1,16 @@ { "compilerOptions": { "module": "commonjs", - "lib": [ - "es6" - ], + "lib": ["es6"], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", - "typeRoots": [ - "../" - ], + "typeRoots": ["../"], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, - "files": [ - "index.d.ts", - "koa-sslify-tests.ts" - ] -} \ No newline at end of file + "files": ["index.d.ts", "koa-sslify-tests.ts"] +}