Skip to content

Instantly share code, notes, and snippets.

@Nukeer
Created December 6, 2019 18:41
Show Gist options
  • Save Nukeer/65da8533936c5d3dc8a61a0d9903fbea to your computer and use it in GitHub Desktop.
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
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