Skip to content

Instantly share code, notes, and snippets.

@ssajous
Forked from gingi/gist:47df42a45bb1653002ee
Last active August 29, 2015 14:16
Show Gist options
  • Save ssajous/3d4dc5e1aa67796353a2 to your computer and use it in GitHub Desktop.
Save ssajous/3d4dc5e1aa67796353a2 to your computer and use it in GitHub Desktop.
function requireHTTPS(req, res, next) {
if (!req.secure) {
//FYI this should work for local development as well
var domain = "https://" + req.get("host");
if (process.env["SSL_PORT"]) {
domain = domain.replace(/:\d+$/, "");
domain += ":" + process.env["SSL_PORT"];
}
return res.redirect(domain + req.url);
}
next();
}
app.use(requireHTTPS);
app.get('/', routeHandlerHome);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment