Skip to content

Instantly share code, notes, and snippets.

@Sitebase
Created February 4, 2015 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sitebase/27a72aad004978d793b3 to your computer and use it in GitHub Desktop.
Save Sitebase/27a72aad004978d793b3 to your computer and use it in GitHub Desktop.
Force https in express
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