Created
February 4, 2015 08:51
-
-
Save Sitebase/27a72aad004978d793b3 to your computer and use it in GitHub Desktop.
Force https in express
This file contains hidden or 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
var app = express(); | |
... | |
app.use(function(req, res, next) { | |
if (req.headers['x-forwarded-proto'] === 'https') { | |
next(); // already on https so just continue | |
else | |
res.redirect('https://' + req.headers.host + req.url); // redirect to https | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment