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..ea21a51 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,19 @@ function applyOptions(options) { return settings; } +function skip(request, options){ + //checks the skip list + let skipList = options.skips; + if(skipList && Array.isArray(skipList)){ + for(let i = 0; i < skipList.length; i++){ + if(request.path.startsWith('/' + skipList[i])){ + return true; + } + } + } + return false; +} + /** * enforceHTTPS * @@ -56,6 +69,11 @@ var enforceHTTPS = function(options) { isHttps = true; } + //checks skips array + if(skip(req, options)){ + isHttps = true; + } + if(isHttps) { next(); } else { 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",