Last active
August 31, 2018 09:39
-
-
Save hampusborgos/07b409d0240cf89f2071 to your computer and use it in GitHub Desktop.
Force HTTPS on Heroku using Express
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
app.use(function (req, res, next) { | |
var sslUrl; | |
if (process.env.NODE_ENV === 'production' && | |
req.headers['x-forwarded-proto'] !== 'https') { | |
sslUrl = ['https://hjnilsson.com', req.url].join(''); | |
return res.redirect(sslUrl); | |
} | |
return next(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment