From 3fee2364dfda7c2beb65dc6e1980e41b2ed30751 Mon Sep 17 00:00:00 2001 From: Ben Grynhaus Date: Sat, 29 Jun 2019 03:58:15 +0300 Subject: [PATCH] add express-sslify types (#36482) --- types/express-sslify/express-sslify-tests.ts | 18 +++++++++++ types/express-sslify/index.d.ts | 32 ++++++++++++++++++++ types/express-sslify/tsconfig.json | 23 ++++++++++++++ types/express-sslify/tslint.json | 1 + 4 files changed, 74 insertions(+) create mode 100644 types/express-sslify/express-sslify-tests.ts create mode 100644 types/express-sslify/index.d.ts create mode 100644 types/express-sslify/tsconfig.json create mode 100644 types/express-sslify/tslint.json diff --git a/types/express-sslify/express-sslify-tests.ts b/types/express-sslify/express-sslify-tests.ts new file mode 100644 index 0000000000..e616b77a1b --- /dev/null +++ b/types/express-sslify/express-sslify-tests.ts @@ -0,0 +1,18 @@ +import { Application } from 'express'; +import { HTTPS } from 'express-sslify'; + +declare const express: Application; +declare const booleanFlag: boolean; + +express.use(HTTPS()); +express.use(HTTPS({})); +express.use(HTTPS({ trustAzureHeader: booleanFlag })); +express.use(HTTPS({ trustProtoHeader: booleanFlag })); +express.use(HTTPS({ trustXForwardedHostHeader: booleanFlag })); +express.use( + HTTPS({ + trustXForwardedHostHeader: booleanFlag, + trustAzureHeader: booleanFlag, + trustProtoHeader: booleanFlag, + }) +); diff --git a/types/express-sslify/index.d.ts b/types/express-sslify/index.d.ts new file mode 100644 index 0000000000..9183c099d7 --- /dev/null +++ b/types/express-sslify/index.d.ts @@ -0,0 +1,32 @@ +// Type definitions for express-sslify 1.2 +// Project: https://github.com/florianheinemann/express-sslify +// Definitions by: Ben Grynhaus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import { RequestHandler } from 'express'; + +export interface Options { + /** + * Heroku, nodejitsu and other hosters often use reverse proxies which offer SSL endpoints but then forward unencrypted HTTP traffic to the website. + * This makes it difficult to detect if the original request was indeed via HTTPS. + * Luckily, most reverse proxies set the x-forwarded-proto header flag with the original request scheme. + * @default false + */ + trustProtoHeader?: boolean; + + /** + * Azure has a slightly different way of signaling encrypted connections. + * To tell express-sslify to look out for Azure's x-arr-ssl header. + * @default false + */ + trustAzureHeader?: boolean; + + /** + * If your reverse proxy sends the original host using the X-Forwarded-Host header and you need to use that instead of the Host header for the redirect. + * @default false + */ + trustXForwardedHostHeader?: boolean; +} + +export function HTTPS(options?: Options): RequestHandler; diff --git a/types/express-sslify/tsconfig.json b/types/express-sslify/tsconfig.json new file mode 100644 index 0000000000..c6705cd3db --- /dev/null +++ b/types/express-sslify/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "express-sslify-tests.ts" + ] +} diff --git a/types/express-sslify/tslint.json b/types/express-sslify/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/express-sslify/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }