From 0028d5fbf15b8033da48e2efc2183e918f0ec32c Mon Sep 17 00:00:00 2001 From: Jordan Meeker Date: Wed, 22 Mar 2017 15:51:37 -0700 Subject: [PATCH 1/3] adds support for excluding certain paths from being redirected --- README.md | 8 ++++++++ index.js | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 3bff555..14cb7e2 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,14 @@ If your reverse proxy sends the original host using the `X-Forwarded-Host` heade app.use(enforce.HTTPS({ trustXForwardedHostHeader: true })) ``` +### Exclude Certain Paths from Being Redirected + +You can exlude a path that starts with given string by including a list called `skips`: + +```javascript +app.use(enforce.HTTPS({ skips: ['/healthcheck'] })) +``` + ## Tests Download the whole repository and call: ```shell diff --git a/index.js b/index.js index 5a0c8de..0ff7584 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,20 @@ function applyOptions(options) { return settings; } +function skip(request, options){ + //checks the skip list + console.log('Request path', request.path) + let skipList = options.skips; + if(skipList && Array.isArray(skipList)){ + for(var i = 0; i < skipList.length; i++){ + if(request.path.startsWith('/' + skipList[i])){ + return true; + } + } + } + return false; +} + /** * enforceHTTPS * @@ -56,6 +70,11 @@ var enforceHTTPS = function(options) { isHttps = true; } + //checks skips array + if(skip(req, options)){ + isHttps = true; + } + if(isHttps) { next(); } else { From 4132e5f51c762d620470cfae17b16f11483c44e3 Mon Sep 17 00:00:00 2001 From: Jordan Meeker Date: Wed, 22 Mar 2017 15:54:14 -0700 Subject: [PATCH 2/3] quick cleanup --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 0ff7584..ea21a51 100644 --- a/index.js +++ b/index.js @@ -25,10 +25,9 @@ function applyOptions(options) { function skip(request, options){ //checks the skip list - console.log('Request path', request.path) let skipList = options.skips; if(skipList && Array.isArray(skipList)){ - for(var i = 0; i < skipList.length; i++){ + for(let i = 0; i < skipList.length; i++){ if(request.path.startsWith('/' + skipList[i])){ return true; } From 1a4ec22fab79aad645b869ab129a8c545ae9e877 Mon Sep 17 00:00:00 2001 From: Jordan Meeker Date: Wed, 22 Mar 2017 16:05:35 -0700 Subject: [PATCH 3/3] updates package.json for npm --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b794a65..78cc684 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "express-sslify", - "version": "1.2.0", + "name": "express-sslify2", + "version": "0.0.1", "description": "Enforces SSL for node.js express projects", "main": "index.js", "scripts": { @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/florianheinemann/express-sslify.git" + "url": "https://github.com/jmeeke02/express-sslify.git" }, "keywords": [ "express", @@ -19,12 +19,12 @@ "http", "redirect" ], - "author": "Florian Heinemann (http://twitter.com/florian__h)", + "author": "Jordan Meeker ", "license": "MIT", "bugs": { - "url": "https://github.com/florianheinemann/express-sslify/issues" + "url": "https://github.com/jmeeke02/express-sslify/issues" }, - "homepage": "https://github.com/florianheinemann/express-sslify", + "homepage": "https://github.com/jmeeke02/express-sslify", "devDependencies": { "chai": "^3.0.0", "express": "^4.13.1",