Express NodeJS – How to redirect HTTP to HTTPS?
Feb 08, 2019 - by kurinchilamp / / Post Comment
In order to redirect HTTP to HTTPS in express server, try adding the following lines to your code base.
app.set('trust proxy', 1);
app.use(function(req, res, next) {
if (! req.secure){
res.redirect("https://" + req.headers.host + req.url);
}
return next();
});
Continue Reading