Created
December 6, 2019 18:41
-
-
Save Nukeer/65da8533936c5d3dc8a61a0d9903fbea to your computer and use it in GitHub Desktop.
Redirect from http to https for the server.js file of node js
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
const app = express(); | |
const forceSSL = function() { | |
return function(req, res, next) { | |
if (req.headers["x-forwarded-proto"] !== "https") { | |
return res.redirect(["https://", req.get("Host"), req.url].join("")); | |
} | |
next(); | |
}; | |
}; | |
app.use(forceSSL()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment