-
-
Save ssajous/3d4dc5e1aa67796353a2 to your computer and use it in GitHub Desktop.
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
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