Closed that1guy closed 9 years ago
@brozeph
@brozeph, should I do this within server.js in htsApp or should we do it inside load balancer.
This isn't working at moment.
//force HTTPS if request is coming from production or staging
app.use(function(req, res, next) {
var host = req.get('host');
if(host === "hashtagsell.com" || host === "www.hashtagsell.com" ) {
host = "www.hashtagsell.com"; //Force url to always contain www
if ((!req.secure) && (req.get('X-Forwarded-Proto') !== 'https')) { //If not https
res.redirect('https://' + host + req.url); //force https
} else {
next();
}
} else if(host === "staging.hashtagsell.com") {
if ((!req.secure) && (req.get('X-Forwarded-Proto') !== 'https')) { //If not https
res.redirect('https://' + host + req.url); //force https
} else {
next();
}
} else {
next();
}
});
Resolved by configuring AWS LB to handle redirect. Thanks @brozeph
I've attempted to resolve this inside server.js in htsApp. We shall see if this works.