Created
April 20, 2017 17:48
-
-
Save brianleroux/9f01866f5a87852fbffe13025c4abc37 to your computer and use it in GitHub Desktop.
express middleware for redirecting to http if a request to nginx came in from http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function HTTPSRedirect(req, res, next) { | |
var env = process && process.env && process.env.NODE_ENV | |
if (env !== 'production' || req.headers['x-forwarded-proto'] === 'https' || req.url === '/health') { | |
next() | |
} | |
else { | |
res.redirect('https://' + req.hostname + req.url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment